IEEE 754 converter: float to binary and hex, and back
Convert a decimal number to its IEEE 754 floating-point bits, or bits back to a number, in single (32-bit) or double (64-bit) precision. The converter colours the sign, exponent and mantissa, shows the exact value that is actually stored, and explains every step. Click any bit to flip it.
On this page
How a floating-point number is stored
IEEE 754 is the standard nearly every processor and programming language uses for non-integer numbers: float and double in C, C++, Java and C#, f32 and f64 in Rust, and every JavaScript number. It writes a number in binary scientific notation,
and packs the three parts into one word of bits:
| Format | Sign | Exponent | Fraction (mantissa) | Bias | Decimal digits |
|---|---|---|---|---|---|
| Single precision (binary32) | 1 | 8 | 23 | 127 | about 7 |
| Double precision (binary64) | 1 | 11 | 52 | 1023 | about 15–17 |
- Sign bit : 0 for positive, 1 for negative.
- Exponent field: the power of two plus a fixed bias (127 or 1023), stored as an unsigned integer. The bias lets the field hold negative exponents without a sign bit, and makes bit patterns of positive floats sort in the same order as their values.
- Fraction field: the bits after the binary point of the significand . A normalised binary number always starts with 1, so that 1 is not stored. This “hidden bit” gives single precision 24 bits of precision from 23 stored ones.
Converting decimal to IEEE 754 by hand
Worked example: −6.25 in single precision
- Sign. The number is negative, so .
- Binary. 6 is
110and 0.25 is.01, so 6.25 = . - Normalise. Move the point two places left: , so .
- Bias the exponent. , which is
10000001in 8 bits. - Fraction. Drop the leading 1 and pad the rest,
1001, with zeros to 23 bits. - Assemble:
1 10000001 10010000000000000000000, which is 0xC0C80000 in hex.
For fractions, convert by repeated doubling: multiply the fractional part by 2, write down the integer digit (0 or 1), and continue with what is left. 0.25 → 0.5 (digit 0) → 1.0 (digit 1), stop. Some fractions never stop, and that is where rounding comes in.
Why 0.1 can’t be stored exactly
Doubling 0.1 gives 0.2, 0.4, 0.8, 1.6, 1.2, 0.4, 0.8, … and the digits 0001 1001 1001 1001 … repeat for ever, just as 1/3 = 0.333… does in decimal. Only fractions whose denominator is a power of two have finite binary expansions. So 0.1 has to be rounded to the nearest number that fits:
- In single precision 0.1 is stored as
0x3DCCCCCD, which is exactly0.100000001490116119384765625, an error of+0.000000001490116119384765625. - In double precision it is
0x3FB999999999999A, exactly0.1000000000000000055511151231257827021181….
Those tiny errors explain the most famous floating-point surprise. In JavaScript or Python, 0.1 + 0.2 prints 0.30000000000000004, and 0.1 + 0.2 == 0.3 is false: both inputs were rounded up slightly, the sum is rounded again, and the result lands on the double just above the one nearest 0.3. Type 0.3 and 0.30000000000000004 into the converter in double precision and compare the bits: they differ in the last place.
Math.abs(a − b) < 1e-9 * Math.max(1, Math.abs(a), Math.abs(b)). And never store money in binary floats: use integer cents or a decimal type.
Rounding: round to nearest, ties to even
When a value falls between two representable numbers, IEEE 754 by default picks the nearer one. On an exact tie it picks the one whose last fraction bit is 0 (“ties to even”), which avoids the steady upward drift that always rounding halves up would cause. You can see this at = 16,777,217: single precision has 24 significant bits, so integers above are spaced 2 apart. 16,777,217 sits exactly halfway between 16,777,216 and 16,777,218 and rounds to the even one, 16777216. That is why a 32-bit float can’t count past 16,777,216 one by one.
The gap between neighbouring floats is called a unit in the last place (ulp). It doubles every time the exponent goes up by one, so floats are dense near zero and sparse for huge values. The converter shows the next value up and down for whatever you type. The ulp of 1 is in single precision and in double; this is machine epsilon.
Special values
The smallest and largest exponent fields are reserved:
| Exponent field | Fraction | Meaning |
|---|---|---|
| All zeros | Zero | ±0. There are two zeros; they compare equal, but . |
| All zeros | Non-zero | Subnormal: no hidden 1, exponent fixed at . They fill the gap between 0 and the smallest normal number, so only when . |
| All ones | Zero | ±∞, the result of overflow or of dividing a non-zero number by zero. |
| All ones | Non-zero | NaN (not a number), from , or . A NaN is not equal to anything, including itself. |
Range of single and double precision
| Single (float) | Double | |
|---|---|---|
| Largest finite | 0x7F7FFFFF ≈ 3.4028235 × 10³⁸ | 0x7FEFFFFFFFFFFFFF ≈ 1.7976931 × 10³⁰⁸ |
| Smallest normal | 0x00800000 = 2⁻¹²⁶ ≈ 1.18 × 10⁻³⁸ | 2⁻¹⁰²² ≈ 2.23 × 10⁻³⁰⁸ |
| Smallest subnormal | 0x00000001 = 2⁻¹⁴⁹ ≈ 1.4 × 10⁻⁴⁵ | 2⁻¹⁰⁷⁴ ≈ 4.9 × 10⁻³²⁴ |
| Machine epsilon | 2⁻²³ ≈ 1.19 × 10⁻⁷ | 2⁻⁵² ≈ 2.22 × 10⁻¹⁶ |
| Exact integers up to | 2²⁴ = 16,777,216 | 2⁵³ = 9,007,199,254,740,992 |
The last row is why JavaScript’s Number.MAX_SAFE_INTEGER is : beyond it, not every integer has a double, so database IDs and 64-bit counters must be handled as strings or BigInt.
Using the converter
- Decimal input accepts ordinary numbers, scientific notation (
6.02e23),Infinity,-0andNaN. The working then shows the encoding steps, and the rounding error compares the exact stored value with exactly what you typed. - Bit input: type
0xfollowed by up to 8 (single) or 16 (double) hex digits, or all 32 or 64 binary digits; spaces are ignored. The working then decodes the bits. - Exact value is computed with arbitrary-precision integers, so it is the true stored value to the last digit, not another rounded float.
- Integers are stored differently, in two’s complement; see the two’s complement calculator.
References
- IEEE Computer Society, IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2019.
- D. Goldberg, “What every computer scientist should know about floating-point arithmetic”, ACM Computing Surveys 23(1), 1991, 5–48.
- R. E. Bryant and D. R. O’Hallaron, Computer Systems: A Programmer’s Perspective, 3rd ed., Pearson, 2016. Section 2.4.
- N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd ed., SIAM, 2002. Chapter 2.