IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

lecture de mot binaire sur 48 bits [Débutant]


Sujet :

MATLAB

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Mars 2015
    Messages : 4
    Par défaut lecture de mot binaire sur 48 bits
    Bonjour,
    Je dois lire un format binaire non connu des classiques float32 ou float64. Je suis en échec sur la routine suivante:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    function [ floatCAP ] = uint48le_to_CAP( mots )
    % récupération de 3 mots uint16 en little endian avec un mots=fread(fid,3,uint16) classique
    % routine inspirée de ci dessous:
    % UINT64LE_TO_VAXD Converts from IEEE-LE (UINT32) to VAXD (double)
    %  This function takes a raw 32bit unsigned integer (little endian)
    %  and converts it into the equivalent floating point number it represents
    %  in the VAXF file format for floating point numbers. The VAXF format is
    %  the single precision format used with both the VAXD and VAXG 
    %  double precision formats and files. 
    %  <a href="http://www.opengroup.org/onlinepubs/9629399/chap14.htm#tagfcjh_20" target="_blank">http://www.opengroup.org/onlinepubs/...htm#tagfcjh_20</a>
    %
    %   See also UINT64LE_TO_VAXG, UINT64LE_TO_VAXD, FREADVAXD, FREADVAXG
     
     
     
    %% Define floating value properties for VAX architecture
    % The generic equation for a floating point number is:
    % (-1)^double(S) * (F+C) * A^(double(E)-B);
    % Different operating systems and file formats utilize different values
    % for A, B, and C. F, E, and S are computed from the appropriate bits in
    % the number as stored on disk.
     
        A = 2   ;%exposant base 2
        B = 128 ;%Complément à 2 de l'exposant
        C = 0.5 ;%biais de normalisation de la mantisse
     
    %% Convert raw unsigned number into right answer
    % Flip the upper and lower bits (based on how Vax data storage format)
    % CAP      <-----mot1-----><-----mot2-----><-----mot3----->
    % IEEE-LE  <-----WORD3-----><-----WORD2-----><-----WORD1----->
     
        mot1  = mots(3);% 
        mot2  = mots(2);%
        mot3  = mots(1);%
     
        CAPInt = bitor( bitshift(mot2, 16), bitshift(mot1, 0) );
        CAPInt = bitor( bitshift(mot3, 32), bitshift(CAPInt,0));%reconstruction des 48 bits
     
    % Pull out the sign, exponent, and fractional component
    % VAX FLOAT BYTES  <-----WORD3----><-----WORD2-----><-----WORD1----->
    % VAX FLOAT BITS   0123456789ABCDEF 0123456789ABCDEF 0123456789ABCDEF
    % Sign Exp Fract   SFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFEEEEEEEE
     
        S = bitshift(bitshift(CAPInt , 0), -47); %)signe
        E = bitshift(bitshift(CAPInt , 40,48), -40);%)exposant
        F = bitshift(bitshift(CAPInt , 1,48),  -9); %   mantisse
     
    % Construct the floating point number from SEF (Sign, Exp, Fract)
    % Formula valid for non-zero values only (zeros fixed in next step)
    % <a href="http://www.codeproject.com/KB/applications/libnumber.aspx" target="_blank">http://www.codeproject.com/KB/applic...libnumber.aspx</a>
    % <a href="http://www.opengroup.org/onlinepubs/9629399/chap14.htm#tagfcjh_20" target="_blank">http://www.opengroup.org/onlinepubs/...htm#tagfcjh_20</a>
     
        M = C+double(F)./1.099511627776e+12;%DACS Specific 1099511627776=2^40 pour normalisation de la mantisse
        floatCAP = (-1).^double(S) .* M .* A.^(double(E)-B);%Generic
     
    % Add in zeros (if E and S are zero, doubleVAXF should be set to zero)
     
        zerosIndex = (E == 0 & S == 0);%logical index of all zeros
        floatCAP(zerosIndex) = 0;
     
        zerosIndex = (E == 0 & S == 1);%cas non défini
        floatCAP(zerosIndex) = NaN;
     
    end
    je joints la description dès que je pourrais mettre une PJ
    Images attachées Images attachées

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Lecture de fichier codé sur 24 bits
    Par vbbarent dans le forum Général Python
    Réponses: 6
    Dernier message: 17/04/2018, 11h35
  2. Comment faire un test binaire sur des bits spécifiques ?
    Par Madmac dans le forum Mathématiques
    Réponses: 2
    Dernier message: 24/01/2016, 21h12
  3. Taille des mots/caractères sur des systèmes de 32/64-bits
    Par nymus7 dans le forum x86 32-bits / 64-bits
    Réponses: 6
    Dernier message: 29/10/2015, 21h49
  4. representation en binaire sur n bits
    Par simpatico dans le forum Débuter
    Réponses: 5
    Dernier message: 11/07/2011, 15h47
  5. lecture binaire sur un flux
    Par zais_ethael dans le forum C++
    Réponses: 9
    Dernier message: 29/08/2006, 01h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo