How a floating-point number is stored
The IEEE 754 standard writes any real number in binary scientific notation: (−1)s × 1.m × 2e − bias. Three fields are stored:
| Format | Sign | Exponent | Mantissa | Bias | Decimal digits |
|---|---|---|---|---|---|
| Single (float, binary32) | 1 bit | 8 bits | 23 bits | 127 | ≈ 7 |
| Double (double, binary64) | 1 bit | 11 bits | 52 bits | 1023 | ≈ 15–16 |
The leading 1 before the binary point is not stored because in a normalized number it is always there: it is the hidden bit, and it gives you one extra bit of precision for free. The exponent is stored in excess (biased) notation so that floats can be compared like unsigned integers.
How to convert a decimal number to IEEE 754 by hand
- Note the sign and keep the absolute value.
- Convert the number to binary: the integer part by repeated division and the fractional part by repeatedly multiplying by 2 (see it step by step in the number base converter).
- Normalize by shifting the binary point until a single 1 remains in front. The number of positions is the exponent E (positive if you move the point to the left).
- Compute the stored exponent: E + 127 in single precision or E + 1023 in double, and write it in binary.
- The mantissa is the bits after the point, padded with zeros or rounded to 23 (or 52) bits.
Example · −13.375 in single precision
13 = 1101 and 0.375 = 0.011, so 13.375 = 1101.011₂ = 1.101011 × 2³. Sign 1; exponent 3 + 127 = 130 = 10000010; mantissa 10101100000000000000000. Put together: 1 10000010 10101100000000000000000 = 0xC1560000.
Special values
- Zero: exponent and mantissa all zeros. Both +0 and −0 exist.
- Denormalized (subnormal) numbers: zero exponent and non-zero mantissa. They represent numbers smaller than the minimum normalized value (≈ 1.18 × 10⁻³⁸ in single precision), without the hidden 1.
- Infinity: exponent all ones and mantissa zero.
- NaN: exponent all ones and non-zero mantissa. Produced by operations like 0/0 or √−1.
Why 0.1 + 0.2 is not 0.3
0.1 has infinitely many digits in binary (0.0001100110011…), so it is stored rounded. In double precision the stored value is slightly greater than 0.1, and so is 0.2, so their sum ends up slightly above the double closest to 0.3. That is why 0.1 + 0.2 == 0.3 is false in almost every programming language: it is not a bug in the language, it is the format. Enter 0.1 above to see the exact value that gets stored.
Frequently asked questions
What is the largest integer that can be stored exactly?
In single precision, 224 = 16,777,216: beyond that not every integer fits (try 16,777,217, which gets rounded). In double precision, 253 = 9,007,199,254,740,992, which is the famous JavaScript Number.MAX_SAFE_INTEGER + 1.
How is the mantissa rounded when it does not fit?
By default, to the nearest value, and on an exact tie to the one ending in 0 ("round half to even"). That way the average error is zero and does not drift in one direction.
What range does each format cover?
Single: from ≈ 1.18 × 10⁻³⁸ to ≈ 3.40 × 10³⁸ normalized (down to ≈ 1.4 × 10⁻⁴⁵ with denormals). Double: from ≈ 2.23 × 10⁻³⁰⁸ to ≈ 1.80 × 10³⁰⁸.
How do I convert a hex value like 0x3DCCCCCD to decimal?
Use the "Hex / binary → decimal" tab: it splits the 32 or 64 bits into sign, exponent and mantissa and rebuilds the value. 0x3DCCCCCD is the single-precision float closest to 0.1.
More computer science tools
Two's Complement Calculator
Signed integers in two's complement, one's complement and sign-magnitude, plus overflow.
OpenKarnaugh Map Solver
Minimal SOP and POS expressions with the groups highlighted on the map.
OpenIPv4 Subnet Calculator
Network, broadcast, hosts, wildcard and VLSM planning with the binary AND.
OpenTruth Table Generator
Truth table for any expression, with minterms and canonical forms.
OpenNumber Base Converter
Binary, octal, decimal, hex and bases 2–36 with repeated division.
OpenSorting Algorithm Visualizer
Animated sorting with comparison and write counters.
Open