A floating point calculator shows exactly how a computer stores a number in the IEEE 754 format. Type a decimal number, such as 0.15625, and you get the sign bit, the exponent bits, the fraction bits and the hex pattern, for single precision (32 bits) or double precision (64 bits). You also see the value that is really stored and how far it is from the number that you typed. The calculator also works in reverse, from a hex pattern to a decimal value. It runs in your browser.
How to use the floating point calculator
- Choose decimal to binary or hex to decimal, and single or double precision.
- Enter the number, or the hex pattern.
- Press Convert.
The layout of a single precision number
The Wikipedia article on the single-precision format says that a binary32 number has 1 sign bit, 8 exponent bits and 23 stored fraction bits, giving 24 bits of precision because the leading bit of a normal number is implied. The exponent has a bias of 127, and the value of a normal number is (−1)^s × 2^(E − 127) × 1.f, where E is the stored exponent and f is the fraction.[1] The calculator shows each of these parts. For 0.15625, the sign is 0, the stored exponent is 124, which is 01111100, and the fraction is 01000000000000000000000. The exponent is 124 − 127 = −3, and the value is 2⁻³ × 1.25, so the pattern in hex is 3E200000. The page gives the number as 2⁻³ × 1.25.[1] The hex pattern is our own working from those fields.
Double precision
The double-precision article describes binary64 as 1 sign bit, 11 exponent bits and 52 fraction bits, with 53 bits of precision, an exponent bias of 1023 and the value (−1)^s × 2^(E − 1023) × 1.f.[2] The same number 1 is 3FF0000000000000 in double precision and 3F800000 in single. The calculator uses the same layout for both formats and changes only the number of bits and the bias. The page also lists double examples such as 3 as 4008000000000000, and π as 400921FB54442D18.[2]
Special values
The articles explain that an exponent of all zeros marks either zero, when the fraction is also zero, or a subnormal number, whose value is (−1)^s × 2^−126 × 0.f in single precision and 2^−1022 × 0.f in double precision. An exponent of all ones marks infinity when the fraction is zero, and NaN, which means not a number, when it is not.[1][2] The calculator names the kind of number and shows the exponent for each. Zero has a sign too: −0 is 80000000 in single precision. Type inf, −inf or nan to see these patterns.
Examples that you can check
The single-precision page lists a number of examples in hex. 1 is 3F800000, 0.25 is 3E800000, 0.375 is 3EC00000, 12.375 is 41460000, 25 is 41C80000, −2 is C0000000, 1/3 is 3EAAAAAB and π is 40490FDB. It also notes that 68.123 is 42883EFA, and not 42883EF9, because of rounding.[1] Enter any of these and the calculator gives the same patterns. The value that you typed for 1/3 is rounded to the nearest 32-bit number, so the stored value is 0.333333343, and the calculator reports the relative error, about 3 parts in 10⁸.
Limits and precision
The largest finite single-precision number is about 3.4028235 × 10³⁸, with the pattern 7F7FFFFF, and the smallest normal number is 2⁻¹²⁶, about 1.1754944 × 10⁻³⁸. The smallest subnormal number is 2⁻¹⁴⁹, about 1.4 × 10⁻⁴⁵.[1] For double precision, the largest is about 1.7976931348623157 × 10³⁰⁸, the smallest normal is about 2.2250738585072014 × 10⁻³⁰⁸ and the smallest subnormal is about 4.94 × 10⁻³²⁴.[2] A number that is too large for the format becomes infinity, and the calculator says so. The articles state that single precision keeps between 6 and 9 significant decimal digits, and that 9 digits are needed to read a stored number back exactly. For double precision the figures are 15 to 17 digits, with 17 needed.[1][2] That is why the calculator shows 9 digits of the stored single value and 17 of the double.
Why 0.1 is not exact
Only numbers that are a sum of powers of two, such as 0.5, 0.25 and 0.15625, can be stored exactly. 0.1 repeats forever in binary, so it must be rounded. In single precision the stored value is 0.100000001, and in double precision it is 0.10000000000000001, which is why a sum such as 0.1 + 0.2 may not equal 0.3 in a program. The calculator shows the stored value and the error, so you can see the effect for yourself and decide how much it matters for your work.
Rounding
The IEEE 754 article names round to nearest, with ties to even, as the default rounding.[3] The calculator relies on your browser, which uses the same rule, so the last bit of the fraction is the nearest one to your number. If the number falls exactly halfway between two values, the one with an even last bit is chosen.
Using the results
Programmers use these patterns to debug code that works with raw bytes, such as file formats and network messages, and to understand why numbers behave as they do. Students use them to learn how a computer represents real numbers. If you see a bit pattern in a memory dump, switch to the hex mode to see the number. If a calculation gives a result that is a little off, enter the numbers and compare the stored values with what you expect.
Common mistakes
- Counting the implied bit. The leading 1 of a normal number is not stored.
- Forgetting the bias. The stored exponent is 127 more than the real one in single precision.
- Typing too few hex digits. Single precision needs 8 and double 16.
- Expecting exact decimals. Most decimal fractions are stored approximately.
What next
Use this often? Add Floating Poi to your Home screen.
Frequently asked questions
What is a floating point calculator?
A tool that converts a decimal number to its IEEE 754 binary form, showing the sign, exponent, fraction and hex pattern, and back.
How is a single precision number stored?
1 sign bit, 8 exponent bits with a bias of 127, and 23 fraction bits. The value is (−1)^s × 2^(E − 127) × 1.f.
What is 0.15625 in IEEE 754 single precision?
3E200000. It is 2⁻³ × 1.25, with a stored exponent of 124.
Why is 0.1 not stored exactly?
Its binary form repeats forever, so it is rounded. The single precision value is about 0.100000001.
What is the difference between single and double precision?
Single uses 32 bits with 24 bits of precision, and double uses 64 bits with 53 bits of precision.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.