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.
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 decimal | 0.1 |
| Rounding error (stored − input) | -0.0000244140625 ≈ -0.0000244141, relative 0.0002441 |
| Hexadecimal | 0x2E66 |
| Binary | 0 01011 1001100110 |
| Sign | 0 (positive) |
| Exponent | field 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 |
| Category | Normal number |
| Gap to next value (ULP) | 2-14 ≈ 0.0000610352 |
| Next value up / down | 0.10004 (0x2E67) 0.0999 (0x2E65) |
Decimal → IEEE 754, step by step
- Sign. The number is positive, so the sign bit is 0.
- Convert |x| to binary. 0.1 = 0.000112 (the overlined block repeats forever).
- Normalize. Move the binary point so one 1 is left of it: |x| = 1.… × 2-4.
- Exponent. Add the bias: -4 + 15 = 11 = 010112.
- 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.
- 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 input | Hex | Exact stored value |
|---|---|---|
| 1 | 0x3C00 | 1 |
| -2 | 0xC000 | -2 |
| 0.5 | 0x3800 | 0.5 |
| 0.1 | 0x2E66 | 0.0999755859375 |
| 1/3 | 0x3555 | 0.333251953125 |
| 3.140625 | 0x4248 | 3.140625 |
| 65504 | 0x7BFF | 65504 |
| 0.00006103515625 | 0x0400 | 0.00006103515625 |
| 100000 | 0x7C00 | Infinity (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
| Meaning | Hex | Exact value |
|---|---|---|
| One | 0x3C00 | 1 |
| Largest finite | 0x7BFF | 65504 |
| Smallest normal | 0x0400 | 0.00006103515625 |
| Largest subnormal | 0x03FF | 0.000060975551605224609375 |
| Smallest subnormal | 0x0001 | 0.000000059604644775390625 |
| Negative zero | 0x8000 | −0 |
| +Infinity | 0x7C00 | +∞ |
| −Infinity | 0xFC00 | −∞ |
| Quiet NaN | 0x7E00 | NaN |
Worked example: decode 0xC500
- Binary:
1 10001 0100000000. - Sign 1 (negative). Exponent field 10001 = 17, so the exponent is 17 − 15 = 2.
- Significand: 1.01000000002 = 1 + 1/4 = 1.25.
- Value: −1.25 × 22 = −5.
Worked example: 3.140625 to half precision
- Binary: 3.140625 = 11.0010012 (3 + 1/8 + 1/64).
- Normalize: 1.1001001 × 21.
- Exponent: 1 + 15 = 16 =
10000. - Fraction (10 bits):
1001001000. - 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).
Related tools and guides
- IEEE 754 converter IEEE 754 converter for single, double, half precision and bfloat16: decimal ↔ hex ↔ binary, clickable bits, the exact stored value and the rounding error.
- 64-bit double precision Convert decimals to IEEE 754 double precision (64-bit) and back: 11 exponent bits, 52 fraction bits, exact stored value, why 0.1 + 0.2 ≠ 0.3.
- Base converter Convert numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36, including fractions with repeating digits, with steps.
- Two's complement Convert between decimal and two's complement binary or hex for any width up to 256 bits. Steps, ranges, one's complement, sign-magnitude and overflow flags.