How to use the ieee 754 float converter
- Choose the format: 32 bit (single, the type many graphics and sensor systems use) or 64 bit (double, the default number type in many languages).
- Choose what you are entering. Pick A decimal number to type a value such as 0.15625, -12.5 or 1e-7 (the words inf and nan also work). Pick Hex digits or Binary digits to decode a bit pattern you already have.
- Type the value. Hex needs exactly 8 digits for a 32 bit float or 16 for a 64 bit float, with or without a leading 0x. Binary needs exactly 32 or 64 digits, and spaces are ignored.
- Read the hex pattern at the top, then the sign, exponent and fraction fields, the kind of number, the shortest decimal that reads back to the same bits and the exact value that is stored. Use Copy or Print to keep the result.
Formula
value = (-1)^sign x 1.fraction x 2^(exponent field - bias) (normal numbers)
value = (-1)^sign x 0.fraction x 2^(1 - bias) (subnormal numbers, exponent field 0)
32 bit: 1 sign bit, 8 exponent bits (bias 127), 23 fraction bits
64 bit: 1 sign bit, 11 exponent bits (bias 1023), 52 fraction bits
An exponent field of all ones means infinity (fraction zero) or not a number (fraction not zero). Decimal text is rounded once, directly to the nearest representable value, with exact ties going to the even fraction.
0.15625 as a 32 bit float
The number 0.15625 is 5/32, which is 1.25 x 2^-3. The sign bit is 0. The exponent is -3, so the exponent field is -3 + 127 = 124, which is 01111100 in binary. The fraction is the .25 part of 1.25, written in 23 bits as 01000000000000000000000.
Putting the three fields together gives 0 01111100 01000000000000000000000, which is 0x3E200000 in hex. Because 0.15625 is a sum of powers of two, nothing is lost: the exact stored value is 0.15625. In contrast, 0.1 has no finite binary form, so the 32 bit float stores 0.100000001490116119384765625 and the 64 bit float stores 0.1000000000000000055511151231257827021181583404541015625.
Why 0.1 is never exactly 0.1
A float stores a whole number of binary fractions, so a decimal fraction is exact only when its denominator is a power of two. One tenth is not, in the same way that one third has no finite decimal form. The stored value is the nearest representable number, and the tiny difference shows up as surprises such as 0.1 + 0.2 not printing as 0.3 in many programs.
The shortest decimal row shows the shortest text that still reads back to the same bits, which is why the stored value of 0.1 is described as 0.1 even though the exact expansion is longer. The two rows together show both the friendly and the true picture.
Subnormal numbers, infinity and not a number
When the exponent field is 0, the number is subnormal: the leading 1 is dropped and the exponent is fixed at the smallest normal value, which lets values closer to zero be stored with less precision instead of jumping to zero. The smallest positive 32 bit float is 2^-149, about 1.4e-45.
The values for infinity and not a number share the all ones exponent. Overflow in conversion gives infinity, and the default not-a-number pattern used here has the top fraction bit set. Other patterns carry payload bits and are shown as entered. For other base conversions, try the number base converter, and for whole numbers see the two's complement converter.
Assumptions and limits
- Only the two common binary formats are covered: 32 bit binary32 and 64 bit binary64. Half precision, 80 bit extended and decimal floating point are not.
- Decimal input is rounded to the nearest representable value with ties to even, the rounding mode most hardware uses by default.
- The exact stored value is shown as a full decimal expansion, shortened with a note when it runs past 70 characters.
- Bit patterns are read as written. Nothing is changed by the byte order of your computer.
Frequently asked questions
What is the difference between a 32 bit and a 64 bit float?
A 32 bit float keeps about 7 significant decimal digits and reaches roughly 3.4e38. A 64 bit float keeps about 15 to 17 digits and reaches roughly 1.8e308. The extra bits go to both a longer fraction and a wider exponent.
How do I read the hex result?
Each hex digit is four bits, so 0x3E200000 is 0011 1110 0010 0000 0000 0000 0000 0000. The first bit is the sign, the next eight are the exponent field and the last 23 are the fraction.
Why can two different decimals give the same float?
Many nearby decimals fall between the same two representable values and round to the same one. A 32 bit float cannot tell 16777216 from 16777217, for example, because above 2^24 it can only store even integers.
Does this tool send my numbers anywhere?
No. The conversion is plain arithmetic in your browser. Nothing you type is uploaded or stored.