The following
describes the make-up of IEEE754 32 bit floating point numbers.
The following format is used throughout wherever floating point
numbers are used.
They are transmitted in the order outlined below, MSB first.
The double words that make up each 32 bit number in a packet are
not order reversed.
Each floating point number cosists of 4 bytes, as follows:
word [------------------ 2 --------------------][----------------------
1 ---------------------]
byte [MSB-----3----][----------2---------][---------1-----------][LSB------0--------
]
bit [7--------------0][7------------------0][7------------------0][7-------------------0]
[SEEEEEEE][EMMMMMMM][MMMMMMMM][MMMMMMMM]
S = SIGN bit where 1 is negative and 0 is positive
E = EXPONENT bits denoting the two's compliment exponent with an
offset of 127
M = MANTISSA bits denoting the normal 23 bit mantissa. The highest
bit of the
mantissa is ALWAYS 1 and is therefore not stored.
Bit 7 of byte 3 (the most significant byte) is the bit that determines
the sign, +ve = 0, -ve = 1. This bit should be sampled and saved.
The byte is then shifted left and byte 2's bit 7 is placed into
the space left in byte 3 bit 0.
A 1 is then placed into byte 2 bit 7 position and an imaginary decimal
point inserted between bit 7 and 6 of this byte.
This action results in byte 3 containing the EXPONENT of the floating
point number and bytes 2 to 0 the mantissa.
EEEEEEEE 1.MMMMMMM MMMMMMMM MMMMMMMM
The exponent value (all bytes are hexadecimal) has 127 subtracted
from it.
A positive result denotes 2 to the power of the resulting exponent,
a negative result denotes 2 to the negative power of the resulting
exponent, i.e. how many places right or left respectively the decimal
point is moved to obtain the absolute real number.
Example.
C1480000h is a hexadecimal number representing a IEEE754 floating
point number and can be displayed as,
1100 0001 (C8h)
byte 3
0100 1000 (48h) byte 2
0000 0000 (00h) byte 1
0000 0000 (00h) byte 0
which is the same as
11000001 01001000 00000000 00000000
Now take byte
3 bit 7 (1) this indicates a negative number, remember it!
Shift all the bits in byte 3 left by 1 bit; result of byte 3 is
1000001x and then replace bit 0 with byte 2 bit 7 (0)
The resulting exponent = 10000010 (this = 1000 0010 or 82h or 130
decimal)
Subtract 127 from this leaving 3.
The mantissa = 1.1001000 00000000 00000000
Now shift the decimal point the number of bits right denoted by
the result of the exponent calc, (3)
1100.1000 00000000 00000000
Binary digits to the left of the decimal point represent the power
of 2 corresponding to their position.
i.e. ordinary binary notation, 1100 = 12 decimal. (1x2^3, 1x2^2,
0x2^1, 0x2^0)
Binary digits to the right of the decimal point represent the negative
power of 2 corresponding to their position.
i.e. ordinary binary notation, 100
.. = 0.5 decimal. (1x2^-1,
1x2^-2, 0x2^-3 etc)
= 12.5
The sign from above is negative, therefore our result = -12.5
|