Skip to content
KmapGen

IEEE 754 16-Bit Half Precision Converter

Convert decimal numbers to IEEE 754 half precision (binary16, FP16) and back. 1 sign bit, 5 exponent bits, 10 fraction bits: see the bits, the exact stored value and how much was lost.

Try:

Decimal input accepts -1.5e-3, fractions like 1/3, C hex floats like 0x1.8p3, pi, inf and nan. Conversion is exact: no intermediate rounding through a double.

Bits (click to flip)

sign · exponent · fraction · bit 15 on the left

Value stored (exact)0.0999755859375
Shortest round-trip decimal0.1
Rounding error (stored − input)-0.0000244140625
≈ -0.0000244141, relative 0.0002441
Hexadecimal0x2E66
Binary0 01011 1001100110
Sign0 (positive)
Exponentfield 01011 = 11; bias 15; actual exponent -4
Fraction (mantissa)1001100110 = 614 / 210 (hidden leading 1 added)
Formula(+1) × 1.599609375 × 211 − 15 = (+1) × 1.599609375 × 2-4
CategoryNormal number
Gap to next value (ULP)2-14 ≈ 0.0000610352
Next value up / down0.10004 (0x2E67)
0.0999 (0x2E65)

Decimal → IEEE 754, step by step

  1. Sign. The number is positive, so the sign bit is 0.
  2. Convert |x| to binary. 0.1 = 0.000112 (the overlined block repeats forever).
  3. Normalize. Move the binary point so one 1 is left of it: |x| = 1.… × 2-4.
  4. Exponent. Add the bias: -4 + 15 = 11 = 010112.
  5. Fraction. Keep the 10 bits after the leading 1. The bits beyond them are not all zero, so the value is rounded to the nearest representable number (ties go to the even one). Fraction = 1001100110.
  6. Assemble sign | exponent | fraction: 0 01011 1001100110 = 0x2E66.

Half-precision layout

  • Sign: bit 15.
  • Exponent: bits 14–10, bias 15. Normal exponents run from −14 (field 00001) to +15 (field 11110).
  • Fraction: bits 9–0, plus the hidden leading 1 for normal numbers: 11 significant bits.
  • Smallest normal: 2−14 ≈ 6.1035 × 10−5 (0x0400). Smallest subnormal: 2−24 ≈ 5.96 × 10−8 (0x0001).
  • Machine epsilon: 2−10 = 0.0009765625. Between 1024 and 2048 the spacing is exactly 1, so integers above 2048 are not all representable.

Half-precision examples

Decimal inputHexExact stored value
10x3C001
-20xC000-2
0.50x38000.5
0.10x2E660.0999755859375
1/30x35550.333251953125
3.1406250x42483.140625
655040x7BFF65504
0.000061035156250x04000.00006103515625
1000000x7C00Infinity (overflow)

Note how 0.1 becomes 0.0999755859375: with only 11 significant bits the error is about 2.4 × 10−5, about 16,000 times larger than in single precision. And 1/3 is stored as 0.333251953125.

Special half-precision bit patterns

MeaningHexExact value
One0x3C001
Largest finite0x7BFF65504
Smallest normal0x04000.00006103515625
Largest subnormal0x03FF0.000060975551605224609375
Smallest subnormal0x00010.000000059604644775390625
Negative zero0x8000−0
+Infinity0x7C00+∞
−Infinity0xFC00−∞
Quiet NaN0x7E00NaN

Worked example: decode 0xC500

  1. Binary: 1 10001 0100000000.
  2. Sign 1 (negative). Exponent field 10001 = 17, so the exponent is 17 − 15 = 2.
  3. Significand: 1.01000000002 = 1 + 1/4 = 1.25.
  4. Value: −1.25 × 22 = −5.

Worked example: 3.140625 to half precision

  1. Binary: 3.140625 = 11.0010012 (3 + 1/8 + 1/64).
  2. Normalize: 1.1001001 × 21.
  3. Exponent: 1 + 15 = 16 = 10000.
  4. Fraction (10 bits): 1001001000.
  5. Result: 0 10000 1001001000 = 0x4248, exact.

Frequently asked questions

What is IEEE 754 half precision?

Half precision (binary16, often called FP16 or float16) is the 16-bit IEEE 754 format: 1 sign bit, 5 exponent bits with a bias of 15, and 10 fraction bits. With the hidden bit it has 11 bits of precision, about 3.3 decimal digits, and a finite range of ±65,504.

What is the largest half-precision number?

65,504, stored as 0x7BFF (exponent field 11110, fraction all 1s): (2 − 2−10) × 215. Any input of 65,520 or more rounds to infinity under the default rounding mode; 65,519.99… still rounds down to 65,504.

What is the difference between FP16 and bfloat16?

Both are 16 bits. FP16 (binary16) spends 5 bits on the exponent and 10 on the fraction: more precision, small range (up to 65,504). bfloat16 keeps float32’s 8-bit exponent and only 7 fraction bits: the same range as float32 (up to about 3.4 × 1038) but only 2–3 significant decimal digits. bfloat16 is simply the top half of a float32.

Where is half precision used?

In GPU shaders and graphics (HDR image formats such as OpenEXR), neural-network training and inference, and anywhere memory bandwidth matters more than precision. JavaScript has Float16Array and Math.f16round, and C/C++ compilers offer _Float16.

Sources

  • IEEE Std 754-2019, IEEE Standard for Floating-Point Arithmetic, IEEE, 2019 (revision of IEEE 754-2008 and IEEE 754-1985).