Using it
Type a number such as 0.1, -2.5 or 6.02e23. The output shows the bits split into sign, exponent and fraction; the rows give the hex, each field, and the value actually stored. If the number can't be stored exactly, the steps say how far off the stored one is. Infinity and NaN work too.
Swap the boxes to decode. Type the bits, or the hex such as 0x3DCCCCCD, and set Precision to match its length: 32 bits for single, 64 for double.
How a float is laid out
A single-precision float is 32 bits: 1 sign bit, 8 exponent bits and 23 fraction bits. Double precision is 64: 1, 11 and 52. The value is (−1)^sign × 1.fraction × 2^(exponent − bias), where the bias is 127 for single and 1023 for double. The leading 1 isn't stored, because every normal number has one, which buys an extra bit of precision for free.
An exponent of all zeros means zero or a subnormal number, a tiny value that gives up the hidden 1 to get closer to zero. An exponent of all ones means infinity if the fraction is zero, and NaN if it isn't.
Why 0.1 + 0.2 isn't 0.3
0.1 in binary is 0.0001100110011… repeating forever, the way 1/3 repeats in decimal. A float has to stop somewhere, so 0.1 is stored as the nearest value it can hold: 0.100000001490116… in single precision. Add two numbers that are each slightly off and the error can show, which is why 0.1 + 0.2 gives 0.30000000000000004 in JavaScript, Python and most other languages that use doubles.
Some values to check against
| Number | Single (hex) | Double (hex) |
|---|---|---|
| 1 | 3F800000 | 3FF0000000000000 |
| -2 | C0000000 | C000000000000000 |
| 0.1 | 3DCCCCCD | 3FB999999999999A |
| 0.5 | 3F000000 | 3FE0000000000000 |
| Infinity | 7F800000 | 7FF0000000000000 |
Questions
What's the difference between single and double precision?
Single uses 32 bits and holds about 7 significant decimal digits; double uses 64 and holds about 15 to 17.
Is −0 different from 0?
As bits, yes: −0 has the sign bit set. They compare as equal, but dividing by them gives −Infinity and Infinity.
Which numbers can be stored exactly?
Those that are a whole number times a power of two within range, such as 0.5, 0.75 and 3.25. Most decimal fractions aren't.
Sources
Added . What's new






