#include <stdio.h>
#include <stdlib.h>
/* D'apres http://fr.wikipedia.org/wiki/IEEE_754 en utilisant le mécanisme 
 * IEEE 754, au format float 32 bits, le nombre -118.625 devrait etre code
 * sur 4 octets : 
 *                C 2 E D 4 0 0 0   (hexa)
 * i. e. 
 *                s × 2^e × m
 * Avec  s = +1 (nombre positif) lorsque le bit de signe est nul.
 *       s = -1 (nombre négatif) lorsque le bit de signe est à 1.
 *       e = Exp - 127
 *       m = 1,fraction (en binaire). D'où 1 <= m < 2.
 * Verifions !
 *
*/
typedef unsigned char uchar;

void decompose( uchar b)
{ int i;
  printf("[%2X]", b);
  for( i = 7; i >= 0; i--)
    printf("%2d", ( ( 1<< i ) & b ) > 0 ); 
}

int main( int argc, char *argv[])
{ float x;
  char exp;
  int mts = 0;
  int i;
  uchar * ptr;
  x = ( float ) atof( argv[1] );
  ptr  = ( uchar * ) &x; 
  ptr += 3;
  for( i = 0; i < 4; i++, ptr--)
    decompose( *ptr );
  putchar('\n');
  ptr  = ( uchar * ) &x; 
  ptr += 3;
  puts("\nSigne : ");
  if ( *ptr & 128 ) putchar('-'); else putchar('+');
  exp = *ptr;
  exp <<= 1;
  ptr++;
  if ( *ptr & 128 ) exp++;
  printf("\nExposant=%d", exp);
  mts = ( *ptr ) & 127;
  ptr--;
  mts = ( mts << 8 ) + *ptr;
  ptr--;
  mts = ( mts << 8 ) + *ptr;
  printf("\nMantisse=%d", mts);
  return 0;
}
