Converting a decimal number to IEEE 754
Floating-point numbers consist of a sign, an exponent and a mantissa. In single precision that is 1 + 8 + 23 bits.
Rules
- Write in binary and normalise: 1.… · 2^e
- Exponent: e + 127
- Mantissa: fraction bits without the leading 1, padded to 23 bits
Your turn
Three problems on this topic. Spaces don’t matter.
- 1 · IEEE 754
- 2
- 3
Represent the number in IEEE 754 single precision (32 bits).
−30.75
Sign (1 bit)
Exponent (8 bits)
Mantissa (23 bits, pad with zeros)
Worked example
Represent the number in IEEE 754 single precision (32 bits).
−34.75
Worked solution
- 1Sign: 1 (negative)
- 2Normalise: 34.75 = 1.… · 2⁵
- 3Exponent: 5 + 127 = 132 = 10000100
- 4Mantissa (without the leading 1): 00010110000000000000000
- 50xC20B0000
Typical mistake: The exponent is stored with a bias of 127, while the leading 1 of the mantissa is not stored at all.
Common questions
Why is the leading 1 not stored?
Normalised numbers always start with 1, which saves a bit.
