IEEE 754 for floating point numbers
Commonly used format for floating point numbers
sign | exponent (binary - excess-127) | fraction | |
---|---|---|---|
32 bits | 0=+ve 1=-ve | 8 | 32 |
64 bits | 0=+ve 1=-ve | 11 | 52 |
Example
- 39.625 (decimal)
- -100111.101 (binary)
- -1.0011101 x 2^5 (normalized binary)
- sign bit = 1
- exponent bit = 5 + 127 = 132 = 1000 0100
- fraction bit = 0011 1101 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
Here we use excess-127 because we want to support negative exponents.
Using 127 allows us to do a comparison on them by natural ordering.