IEEE 754 floating-point converter

Enter a decimal number to see its sign, exponent and significand bits, color-coded, and its hex pattern in IEEE 754 half (16-bit), single (32-bit) and double (64-bit) precision. The exact stored value is shown as a full decimal along with its error from your input, so you can see why 0.1 cannot be stored exactly and how precision and range differ between formats. You can also edit the hex pattern to decode it back to a value.

Inputs

Results

Sign Exponent Significand

Hex
–
Class
–
Sign
–
Exponent
–
Significand
–
Exact stored value
–
Error (stored − input)
–

Format properties

Precision
–
Machine epsilon
–
Largest value
–
Smallest normal
–
Smallest subnormal
–

Rounding is round to nearest, ties to even. Editing the hex field decodes that bit pattern back to a value.

Sign, exponent, significand and the bias

An IEEE 754 number stores a value as (−1)^sign × 1.significand × 2^(exponent − bias). Half precision uses 1 sign bit, 5 exponent bits and 10 significand bits; single uses 1, 8 and 23; double uses 1, 11 and 52. The biases are 15, 127 and 1023. Storing the true exponent plus a bias lets negative exponents be handled as unsigned integers. For normal numbers the leading digit of the significand is always 1, so it is not stored (the hidden bit), which gives single precision 24 bits of precision from 23 stored bits. The tool color-codes the three fields and shows the exponent as “stored value − bias = true exponent”.

Worked example: 0.1 in single precision

In binary, 0.1 is 0.000110011001100…, with 0011 repeating forever; normalized, it is 1.10011001100…(2) × 2⁻⁴. In single precision the stored exponent is −4 + 127 = 123 (0111 1011). Cutting the significand after 23 fraction bits leaves a remainder greater than half, so it rounds up to 10011001100110011001101. Put together, the pattern is 0 01111011 10011001100110011001101, or 0x3DCCCCCD. The value this pattern actually represents is 0.100000001490116119384765625, an error of about 1.49 × 10⁻⁹. A fraction whose denominator is not a power of two has no finite binary expansion, so 0.1 cannot be exact at any width. In double precision it becomes 0x3FB999999999999A and the error shrinks to about 5.55 × 10⁻¹⁸, but it never reaches zero.

Subnormals, zero, infinity and NaN

Exponent fields of all zeros and all ones are reserved for special values. All-zero exponent with a zero significand is zero (+0 or −0 depending on the sign bit); with a nonzero significand it is a subnormal number. Subnormals drop the implied leading 1 and represent 0.significand × 2^(1 − bias), filling the gap between zero and the smallest normal number (2⁻¹²⁶ ≈ 1.175 × 10⁻³⁸ in single) with evenly spaced values. This is called gradual underflow, and the smallest subnormal in single precision is 2⁻¹⁴⁹ ≈ 1.401 × 10⁻⁴⁵. The smaller a subnormal gets, though, the fewer significant bits it has. When the exponent is all ones, a zero significand means infinity and a nonzero one means NaN. In single precision, try 1e-40 to get a subnormal and 1e39 to get infinity.

Rounding, machine epsilon and calculation error

A value that cannot be represented is rounded to the nearest representable one, and an exact tie goes to the one whose last significand bit is 0 (round half to even). The gap between 1 and the next larger representable number is the machine epsilon: 2⁻¹⁰ ≈ 9.766 × 10⁻⁴ for half, 2⁻²³ ≈ 1.192 × 10⁻⁷ for single and 2⁻⁵² ≈ 2.220 × 10⁻¹⁶ for double. In the normal range, the relative rounding error is at most half of that. The error becomes a problem when calculations magnify it. Subtracting nearly equal numbers cancels the leading digits and leaves few significant ones (catastrophic cancellation), and adding numbers of very different size loses the low digits of the smaller one (absorption). Enter 1.0000001 in single precision and it is stored as 1.00000011920928955078125, so subtracting 1 gives about 1.19 × 10⁻⁷, nearly 20% more than the true 1 × 10⁻⁷. Enter 100000001 and it becomes 100000000, so adding 1 to 100 million changes nothing. Note that for single and half precision the tool first converts the input to a double and then rounds that, so for inputs extremely close to a tie the last bit can differ from rounding the decimal directly.

Half precision, bfloat16 and AI

Half precision (FP16) halves memory and bandwidth compared with single, but its 5-bit exponent limits the largest value to 65504 and the smallest normal to 2⁻¹⁴ ≈ 6.104 × 10⁻⁵. In the tool, 65519 rounds to 65504 and anything from 65520 up becomes infinity. Training neural networks in FP16 relies on loss scaling to keep small gradients from flushing to zero. bfloat16 is a 16-bit format with 1 sign, 8 exponent and 7 significand bits; sharing single precision's exponent, it covers nearly the same range, but its precision is only 8 bits, about 2.4 decimal digits. Its layout matches the upper 16 bits of a single, which makes conversion simple, and it is widely used for AI training. This tool does not implement bfloat16 or FP8. To get a bfloat16 value, take the upper four hex digits of the single-precision pattern and round off the lower 16 bits to nearest even. For 0.1, the single pattern is 0x3DCCCCCD; the lower CCCD is more than the halfway point 8000, so it rounds up to bfloat16 0x3DCD (0.10009765625).

Practice computer arithmetic questions

Converting −6.25 to single precision, what is the sign–exponent–significand bit string written in hexadecimal?

  1. A0xC0C80000
  2. B0x40C80000
  3. C0xC0A80000
Show answer and explanation

Answer: A. 0xC0C80000

6.25 in binary is 110.01, normalized as 1.1001 × 2². The sign is negative, so 1; the stored exponent is 2 + 127 = 129 = 1000 0001; and the significand is the fraction 1001 followed by zeros. Laid out, 1 10000001 1001000…0 groups into 1100 0000 1100 1000 0000 …, which is 0xC0C80000. 0x40C80000 has sign bit 0 and represents +6.25, and 0xC0A80000 has significand 0101 and represents −5.25.

Which correctly describes representing decimal 0.1 as a binary floating-point number?

  1. AIt can be represented exactly as 0.1 in binary too, so no error arises
  2. BIt becomes an infinitely repeating binary fraction, so a nearby rounded value is stored
  3. CIn binary, it becomes exactly ten times larger than the original value
Show answer and explanation

Answer: B. It becomes an infinitely repeating binary fraction, so a nearby rounded value is stored

Decimal 0.1 in binary is 0.000110011001100…, with 0011 repeating forever. A floating-point significand has limited digits, so only a nearby rounded value can be stored, introducing a small error. Any fraction whose denominator is not a power of two cannot be written in finitely many binary digits, whereas numbers such as 0.5 and 0.25 are exact. No conversion makes the value ten times larger.

What is the largest finite value representable in FP16 (1 sign, 5 exponent bits with bias 15, 10 significand bits)?

  1. A32768
  2. B65536
  3. C65504
Show answer and explanation

Answer: C. 65504

An all-ones exponent (31) is reserved for infinity and NaN, so the maximum exponent field is 30, giving a true exponent of 30 − 15 = 15. With an all-ones significand, the value is (1 + 1 − 2⁻¹⁰) × 2¹⁵ = (2 − 2⁻¹⁰) × 32768 = 65536 − 32 = 65504. Anything larger becomes infinity, so overflow must also be watched when training in FP16. 32768 is 2¹⁵ with a zero significand, and 65536 is 2¹⁶; neither is the maximum.

FAQ

What is 0.1 in single precision hex?

0x3DCCCCCD. The sign is 0, the stored exponent is 123 (true exponent −4) and the significand is 1.10011001100110011001101(2), so the value actually stored is 0.100000001490116119384765625. In double precision it is 0x3FB999999999999A, and in half precision 0x2E66.

Why does 0.1 + 0.2 not equal 0.3?

None of 0.1, 0.2 and 0.3 can be represented exactly in binary, so each is rounded to a nearby value. In double precision, 0.1 and 0.2 are stored slightly high and 0.3 slightly low, which you can see from the sign of the error in the tool. The sum 0.1 + 0.2 comes out as 0.3000000000000000444…, pattern 0x3FD3333333333334, one unit in the last place away from 0.3's pattern 0x3FD3333333333333. Compare floating-point numbers by checking whether their difference is small enough.

What is the machine epsilon of single and double precision?

Defined as the gap between 1 and the next larger representable number, it is 2⁻²³ ≈ 1.192 × 10⁻⁷ for single, 2⁻⁵² ≈ 2.220 × 10⁻¹⁶ for double and 2⁻¹⁰ ≈ 9.766 × 10⁻⁴ for half. Some texts use half of this value, the maximum relative rounding error, under the same name, so check which definition is meant.

Up to what integer is single precision exact?

With 24 bits of precision, every integer up to 2²⁴ = 16777216 is exact. 16777217 lies exactly halfway between 16777216 and 16777218, so round half to even stores it as 16777216, with an error of −1. Double precision is exact up to 2⁵³ = 9007199254740992, and half precision up to 2¹¹ = 2048.

How do I decode a hex bit pattern?

Type it into the “Bit pattern (hex)” field, using no more digits than the format holds (4 for half, 8 for single, 16 for double), and the tool splits it into sign, exponent and significand and shows the value. In single precision, for example, 3F800000 is 1, C0C80000 is −6.25, 7F800000 is +∞ and 7FC00000 is NaN. A leading 0x is accepted.

Related terms

IEEE 754 Significand Exponent field Subnormal number Round half to even Machine epsilon Catastrophic cancellation Floating-point absorption bfloat16

Related calculators

Semiconductor, Electronics and Computing Calculators →