IEEE 754 floating point converter
Convert decimal numbers to IEEE 754 binary, or decode a bit pattern. Choose 32-bit or 64-bit precision to explore the sign, exponent, and mantissa.
How this tool works
Turn a decimal number into its IEEE 754 bit pattern at half (16-bit), single (32-bit) or double (64-bit) precision, or paste a hex pattern to decode it, with the sign, exponent (raw and unbiased), and mantissa broken out and the full bit string colour-coded. Special values (zero, infinity, NaN, and subnormals) are named. Single and double conversions are done by the browser's own floating-point hardware, the same way your CPU does; half precision is rounded to nearest, ties to even, and checked against all 65,536 half patterns.
How to use it
Pick 16-bit, 32-bit or 64-bit precision, then type a number in the Decimal value
box, including scientific notation like 1e10, or the words
inf and nan. The
Bit pattern box updates with the hex encoding, and you can type a pattern
there instead (0x hex or 0b binary) to
decode it back to a value. The breakdown shows each field, and the coloured bit string maps
every bit to the sign, exponent, or mantissa it belongs to.
How IEEE 754 works
A floating point number is stored like scientific notation in binary:
value = sign x 1.mantissa x 2^(exponent - bias). The
sign is one bit. The exponent is stored with a bias added
(15 for 16-bit, 127 for 32-bit, 1023 for 64-bit) so it is
always non-negative; subtract the bias to get the real power of two. The
mantissa holds the fraction after an implied leading
1. for normal numbers. This is why the same fixed number of bits
can span both enormous and tiny magnitudes, trading exactness for range.
Why 0.1 + 0.2 is not 0.3
Type 0.1 at 64-bit and you get 0x3FB999999999999A,
which is really 0.1000000000000000055.... The value
0.1 has no exact binary representation (just as
1/3 has no exact decimal one), so it rounds to the nearest
representable number. Add two such rounded values and the small errors can survive, which is
the famous reason 0.1 + 0.2 prints as
0.30000000000000004 in most languages. Fixed-point avoids this for
money; see fixed-point and
floating point.
Frequently asked
How does IEEE 754 store a number?
As three fields: a sign bit, a biased exponent, and a fractional mantissa, meaning sign times 1.mantissa times 2 to the (exponent minus bias). A 16-bit half uses 1, 5 (bias 15) and 10 bits; a 32-bit float uses 1, 8 (bias 127), and 23 bits; a 64-bit double uses 1, 11 (bias 1023), and 52.
What is half precision floating point?
Half precision is IEEE 754 binary16: 1 sign bit, 5 exponent bits with a bias of 15, and 10 mantissa bits. Its largest value is 65504, its smallest normal value is 2^-14 (about 0.000061) and its smallest subnormal 2^-24 (about 0.00000006), with about 3 significant decimal digits. 0.1 in half precision is 0x2E66, which is really 0.0999755859375.
What is 0.1 in IEEE 754?
0.1 has no exact binary form, so it is stored as the nearest value: 0x3DCCCCCD (about 0.100000001) in 32-bit, or 0x3FB999999999999A (about 0.1000000000000000055) in 64-bit. That rounding is why 0.1 + 0.2 is not exactly 0.3.
Why is the exponent biased?
Adding a bias (127 or 1023) keeps the stored exponent non-negative, so one unsigned comparison orders both tiny and huge magnitudes. Subtract the bias to recover the real exponent.
How are infinity and NaN stored?
Both use an all-ones exponent: an all-zero mantissa is infinity (the sign bit picks the direction), a non-zero mantissa is NaN. An all-zero exponent with a non-zero mantissa is a subnormal, for values below the smallest normal number.
How do you convert an IEEE 754 hex value to decimal?
Split the bits into sign, exponent and fraction. For the 32-bit pattern 40D00000: the sign is 0, the exponent field is 129, so the power is 2^(129 - 127) = 4, and the fraction gives 1.625; 1.625 x 4 = 6.5. Paste a hex pattern into the converter to see these steps done for you.
Floating point is how computers hold real numbers. Read the floating point lesson and its cousin fixed-point, or open the lab and build the integer arithmetic it is layered on. For how this compares with fixed point, see fixed point vs floating point.
Related tools: binary converter, two's complement calculator, and bitwise calculator.
Open the lab →