IEEE 754 float converter
What is an Ieee 754 Float Converter?
Almost every computer stores fractional numbers in the IEEE 754 floating-point format. Understanding its bit layout explains surprising behaviour, like why 0.1 + 0.2 is not exactly 0.3 in JavaScript, Python and most other languages. This converter shows the exact bits of single-precision (32-bit) and double-precision (64-bit) values.
How to use it
- Enter a decimal number, or a hex or binary bit pattern.
- See the sign, exponent and mantissa fields, the hex representation and the exact stored value.
The layout
- Single (float32): 1 sign bit, 8 exponent bits (bias 127), 23 fraction bits. About 7 significant decimal digits.
- Double (float64): 1 sign bit, 11 exponent bits (bias 1023), 52 fraction bits. About 15 to 17 significant digits.
Value = (-1)^sign × 1.fraction × 2^(exponent - bias) for normal numbers.
Worked example
-6.25 = -1.5625 × 2². Sign = 1, exponent = 2 + 127 = 129 = 10000001, fraction = .5625 = 1001000.... As float32 the bits are 1 10000001 10010000000000000000000, or 0xC0C80000.
Why 0.1 is inexact
0.1 has no finite binary representation, just as 1/3 has none in decimal. The nearest double is 0.1000000000000000055511151231257827. Adding two such approximations gives 0.30000000000000004.
Special values
- Exponent all ones with zero fraction: positive or negative infinity.
- Exponent all ones with non-zero fraction: NaN.
- Exponent all zeros: zero (positive and negative) and subnormal numbers.
For money, use integers or decimal types instead of floats.
Frequently Asked Questions
Why is 0.1 plus 0.2 not equal to 0.3?
Neither 0.1 nor 0.2 can be stored exactly in binary floating point, so their sum is a tiny bit off from 0.3.
What is the difference between float and double?
A float uses 32 bits with about 7 significant digits. A double uses 64 bits with about 15 to 17 significant digits.
What is the exponent bias?
A constant added to the real exponent so it can be stored as an unsigned number: 127 for single and 1023 for double precision.
Why are there two zeros?
The sign bit is separate, so IEEE 754 has both positive and negative zero. They compare as equal.