How IEEE 754 stores a float
A 32-bit float holds three fields: one sign bit, an 8-bit exponent and a 23-bit fraction.
The stored exponent carries a bias of 127, so the real exponent is the stored value minus 127.
The value is the fraction with an implied 1 in front, scaled by two to the power of the exponent.
Try the IEEE 754 float format in the bit editor
The bits of the float 1.0, which is 0x3F800000. Edit the expression or select a bit to flip it.
- hex
- 0x3F800000
- value
- 1065353216
The IEEE 754 float format step by step
Read the three fields of the float in the editor: The steps follow the value above.
- Write the 32 bits: 00111111100000000000000000000000
- The sign bit is 0, so the value is positive.
- The next 8 bits are the exponent: 01111111, which is 127. Subtract the bias 127 to get 0.
- The last 23 bits are the fraction: 00000000000000000000000
- The value is 1.
The three fields of a 32-bit float
| Field | Bits | Width | Purpose |
|---|---|---|---|
| Sign | 31 | 1 | The value 1 marks a negative number |
| Exponent | 30 to 23 | 8 | The power of two, with a bias of 127 |
| Fraction | 22 to 0 | 23 | The digits after the implied 1 |
Where the IEEE 754 float format is used
A sensor that reports a float over a serial link sends these four bytes.
A firmware that logs a float to flash stores the same 32 bits.
A value that looks wrong in a log is often a float read as an integer.
The IEEE 754 float format: points to note
- The bits of the float 1.0 give 1065353216 as an unsigned integer. The two readings share the same bits.
- The expression field takes a float, such as 0.5, and shows the 32 bits of it.
- The exponent 0 and the exponent 255 are special. They mark zero, a subnormal value, an infinity and a NaN.
- A float has about 7 decimal digits of precision. A 32-bit integer above 16777216 does not survive a round trip.
- The byte order of a float follows the byte order of the target, so a float over a link needs a defined order.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about the IEEE 754 float format
- What is 1.0 in binary?
- The float 1.0 is 0x3F800000. The sign bit is 0, the exponent is 127 and the fraction is 0.
- Why does 0.1 have no exact form?
- A float holds a sum of powers of two. The value 0.1 needs an endless sum, so the stored value is the nearest one.
- How wide is a double?
- A double holds 64 bits: one sign bit, an 11-bit exponent with a bias of 1023, and a 52-bit fraction.
- How do I see the bits of my own value?
- Enter the float in the expression field, such as 0.5. The 32 bits change at once.