Feb 14
Finish discussion of floating point :
The attached little.c looks
at a floating point version of 0x1234,
in part to see if the bytes were
reversed in little-endian form.
And the answer is ... *yes* the
floating point is little-endian.
The bytes need to be reversed
before parsing into (sign, exponent, fraction).
/* from little.c */
int i = 0x1234;
float x = 0x1234;
float y = 0x2468;
show_bytes(&i, 4);
show_bytes(&x, 4);
show_bytes(&y, 4);
$ ./little
at 0xbff9b67c : 0x34 0x12 0x0 0x0 # i bytes are reversed
at 0xbff9b678 : 0x0 0xa0 0x91 0x45 # x ditto
at 0xbff9b674 : 0x0 0xa0 0x11 0x46 # y ditto
Reversed to undo little-endian :
i integer bytes : 0x 00 00 12 34
x float bytes : 0x 45 91 a0 00
and those float bytes as bits are
0100 0101 1001 0001 1010 0000 0000 0000
which are organized as (1 sign bit, 8 exp bits, 23 frac bits)
0 10001011 00100011010000000000000
With the (implied) leading 1, the value mantissa=1+frac is
100100011010000000000000
which with the exponent handled correctly is actually
1 0010 0011 0100
1 2 3 4 ... which is the 0x1234 .
machine code
We took a brief tour of some ideas from chapter 3.
my examples :
Also see