TTKTheTextKit

IEEE 754 Float Converter

Type a decimal such as 0.1, or paste a hex or binary pattern, and see how it is stored as a 32 bit float or a 64 bit double. The tool splits the bits into sign, exponent and fraction, tells you whether the number is normal, subnormal, zero, infinity or NaN, shows the exact decimal value that is really stored, and gives the shortest decimal that reads back as the same number. Everything runs in your browser.

Sign
0
Exponent (8)
01111011
Fraction (23)
10011001100110011001101
Hex
0x3DCCCCCD
Binary
00111101110011001100110011001101
Type
Normal
Exponent -4 (field 123)
Shortest decimal
0.1
The fewest digits that read back as this number
Exact value stored
0.100000001490116119384765625
The next larger number is 7.45058e-9 away (one unit in the last place).
Limits of the 32 bit format
Limit of 32 bitValueHex
Largest finite3.4028235e+387F7FFFFF
Smallest normal1.1754944e-3800800000
Smallest subnormal1e-4500000001

A binary floating point number is stored as three fields: a sign bit, an exponent and a fraction. A 32 bit float uses 1, 8 and 23 bits, and a 64 bit double uses 1, 11 and 52. For a normal number the value is (1 + fraction) x 2^(exponent minus bias), with a bias of 127 or 1023. Most decimals, such as 0.1, have no exact binary form, so the nearest stored number is slightly off, and that is why 0.1 + 0.2 shows as 0.30000000000000004 in a double. The exact value shown is the full decimal expansion of what is really stored. An all-ones exponent means infinity or NaN, and an all-zero exponent means zero or a subnormal number. Everything is worked out in your browser and nothing is uploaded.

Related Tools

[5 suggestions]

About the IEEE 754 Float Converter

Most programming languages store non-integer numbers as IEEE 754 binary floating point. A 32 bit float has 1 sign bit, 8 exponent bits and 23 fraction bits. A 64 bit double has 1, 11 and 52. For a normal number the value is (1 + fraction) x 2 to the power of (exponent minus bias), with a bias of 127 for a float and 1023 for a double. An exponent of all ones means infinity (fraction zero) or NaN, and an exponent of all zeros means zero or a subnormal number, which trades precision for a smaller range near zero. Because the fraction is binary, most decimals have no exact form. The number 0.1 is stored as the nearest float, 0.100000001490116119384765625 (hex 3DCCCCCD), or as the nearest double, 0.1000000000000000055511151231257827021181583404541015625 (hex 3FB999999999999A). That small error is why 0.1 + 0.2 gives 0.30000000000000004. Above 16,777,216 a 32 bit float can no longer store every whole number, so 16,777,217 is stored as 16,777,216, and a double does the same above 9,007,199,254,740,992. The tool shows the gap to the next number, which is the unit in the last place, and the limits of each format: the largest finite float is about 3.4028235e38 and the largest double about 1.7976931348623157e308. Nothing is uploaded.

How is a floating point number stored?▾

As three fields: a sign bit, an exponent and a fraction. A 32 bit float uses 1, 8 and 23 bits, and a 64 bit double uses 1, 11 and 52. The value is (1 + fraction) x 2 to the power of (exponent minus bias) for a normal number.

Why is 0.1 + 0.2 not exactly 0.3?▾

Neither 0.1 nor 0.2 has an exact binary form, so each is stored as the nearest double. Their sum rounds to 0.30000000000000004, which is a different double from the one stored for 0.3.

What is the difference between float and double?▾

A float has 24 significant bits, about 7 decimal digits, and a double has 53, about 15 to 17 digits. A double also has a far larger range. The float is half the size, which matters for graphics and large arrays.

What are subnormal numbers?▾

They are numbers smaller than the smallest normal value, stored with an exponent of all zeros and no hidden leading one. They fill the gap between zero and the smallest normal number, with less precision as they shrink.

Is my data uploaded?▾

No. The conversion runs in your browser and nothing you enter is sent anywhere.