A half precision floating point calculator converts a decimal number into its 16-bit binary16 representation (IEEE 754-2008) and back, showing the sign, exponent, and fraction bits. You enter a real number, and the calculator gives you the exact half-precision bits, the decimal value those bits represent, and the rounding error.
Formula
The IEEE 754 half-precision format (binary16) uses 16 bits total: 1 sign bit, 5 exponent bits, and 10 fraction bits (plus an implicit leading 1 for normal numbers). The value of a normal half-precision number is:
value = (−1)sign × 2(exponent − 15) × (1 + fraction/1024)
where:
- sign is 0 for positive, 1 for negative
- exponent is a 5-bit integer from 1 to 30 (0 and 31 are special)
- fraction is a 10-bit integer from 0 to 1023
- The bias is 15 (so exponent − 15 gives the actual power of two)
For subnormal numbers (exponent = 0), the formula becomes (−1)sign × 2−14 × (fraction/1024). Zero is represented by all bits zero (or sign bit set for −0). Infinity has exponent 31 and fraction 0; NaN has exponent 31 and fraction ≠ 0.
Worked Example
Take the default value x = 1.5.
- Sign: positive, so sign bit = 0.
- Exponent: the largest power of 2 ≤ 1.5 is 1 (20), so exponent = 0 + 15 = 15, binary 01111.
- Fraction: 1.5 = 1 + 0.5, so fraction = 0.5 × 1024 = 512, binary 1000000000.
- Bits: 0 01111 1000000000 = 0x3E00.
- Stored value: (−1)0 × 2(15−15) × (1 + 512/1024) = 1 × 1 × 1.5 = 1.5.
- Absolute error: |1.5 − 1.5| = 0.
The calculator shows bits 0x3E00, value 1.5, error 0.
Why Use Half Precision?
Half precision (16-bit floats) is used in machine learning, graphics (HDR images, GPUs), and embedded systems where memory bandwidth and storage are limited. It halves the memory footprint compared to single precision (32-bit) and quarters it compared to double precision (64-bit). The trade-off is range and precision: half floats can represent numbers from about ±6.1×10−5 (subnormal) to ±65504, with about 3–4 significant decimal digits. For many neural network inference tasks, that is enough, and the speed gain is significant.
How to Read the Result
The first output bits shows the 16-bit pattern as three groups: sign, exponent, fraction. The second output stored value is the decimal number that the bits actually represent (after rounding). The third output absolute error is the difference between your original input and the stored value. If you enter 0.1, the stored value is approximately 0.099975586, so the error is about 2.44×10−5. That is the precision loss you get with half floats.
Common Mistakes
- Ignoring subnormals: Numbers below 6.1×10−5 lose precision gradually; the calculator handles them, but many naive converters do not.
- Rounding mode: The calculator uses round-to-nearest-even, the default. Other modes (toward zero, toward +∞) give different bits for values exactly halfway between representable numbers.
- Overflow: Any number with absolute value greater than 65504 becomes infinity. The calculator rejects inputs beyond that range.
- Negative zero: −0 is a valid half float with sign bit 1 and all other bits 0. The calculator shows it correctly.
Limitations of the Formula
The half-precision format cannot represent most decimal fractions exactly because the denominator is a power of two. For example, 0.1 in binary is a repeating fraction, so it is always rounded. The absolute error grows with the magnitude of the number because the spacing between representable numbers increases. Near 65504, the gap is 32, so a number like 65490 might be stored as 65488 or 65504. The relative error stays around 2−11 ≈ 0.000488, but the absolute error can be large.
Alternatives and Extensions
If you need more precision, use single precision (32-bit, 23 fraction bits) or double precision (64-bit, 52 fraction bits). For even smaller storage, bfloat16 (used in some AI accelerators) has 8 exponent bits and 7 fraction bits, giving a wider range but less precision. The calculator here is for the standard IEEE half, which is what most CPUs and GPUs support.
Frequently Asked Questions
What is the range of half precision?
The largest finite value is 65504, and the smallest positive normal value is about 6.1×10−5. Subnormals go down to about 5.96×10−8.
Why does 0.1 become 0.099975586?
Because 0.1 in binary is an infinite repeating fraction (0.000110011…). The 10-bit fraction cannot store it exactly, so it rounds to the nearest representable value, which is 0.0999755859375.
Can I convert a half float back to decimal?
Yes, the calculator does that automatically. Enter the decimal value you have, and it shows the bits and the exact decimal value those bits represent.
What is the difference between half and bfloat16?
Half has 10 fraction bits and 5 exponent bits. Bfloat16 has 7 fraction bits and 8 exponent bits, so it has a wider range but less precision. Bfloat16 is used in some deep learning frameworks because it matches the range of single precision.
How do I round a decimal to the nearest half float manually?
Find the exponent by taking log2 of the absolute value and clamping to the range. Then compute the fraction as (|x| / 2exp − 1) × 1024, round to the nearest integer, and handle carries (if fraction rounds to 1024, increment the exponent). The calculator does this automatically.
Related
Formula used
in x | Decimal number | - | 1.5 | -65504 | 65504 out bits | Binary16 (hex) | - | (if x >= 0, '0' else '1') + ' ' + dec2bin(floor((log2(abs(x)) + 15)) + 1, 5) + ' ' + fracbits(x) | 0 out value | Stored value | - | (if x >= 0, 1 else -1) * (2 ^ (floor(log2(abs(x))) - 15)) * (1 + fracval(x)) | 6 out error | Absolute error | - | abs(x - ((if x >= 0, 1 else -1) * (2 ^ (floor(log2(abs(x))) - 15)) * (1 + fracval(x)))) | 6
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Measuring Light Speed & Wavelength: How It Works
- Draco Race Blox Fruits: How to Get It
- How to Automatically Create a Table of Contents
- No Loss Persistence: Data Protection at Every Boundary
- ES File Explorer Tips & Tricks That Actually Work
- Remove Google FRP Lock on Oppo: Step-by-Step