IEEE 754 Converter: Float to Hex (Single, Double, Half and bfloat16)
An IEEE 754 float stores a sign, a biased exponent and a fraction: 1, 8 and 23 bits in binary32 (float). 0.1 is not representable exactly: it is stored as 0x3DCCCCCD, which is exactly 0.100000001490116119384765625, a rounding error of 1.49e-9. The converter works both ways and gives the bit fields, the exact stored value, the error in ulps, the bytes, and the same number as double, half and bfloat16.
0x3DCCCCCD
(−1)^0 × 1.fraction × 2^(123 − 127)
0.1 as binary32 (float) is stored as 0.1
IEEE 754-2019 encoding, round to nearest with ties to even, computed with exact integers from the decimal you type: no double rounding through binary64. The exact stored value is the dyadic rational the bits encode. NaN payloads are not preserved: nan encodes as the canonical quiet NaN. Values and hex are written with a decimal point, as in code.
A misunderstood float in firmware means a reading wrong in the last digit or a test that fails at random. We write the firmware for our boards, from sensor driver to signal processing. Let's talk about your project in a free 30-minute audit.
The four float formats at a glance
Field widths, bias and limits as computed by the tool.
| Format | Bits (s, exp, fraction) | Bias | Largest finite | Smallest normal | Epsilon | Round-trip digits |
|---|---|---|---|---|---|---|
| binary16 (half) | 16 (1, 5, 10) | 15 | 65504 | 6.1035e-5 | 2^−10 | 5 |
| bfloat16 | 16 (1, 8, 7) | 127 | 3.39e+38 | 1.18e-38 | 2^−7 | 4 |
| binary32 (float) | 32 (1, 8, 23) | 127 | 3.4028235e+38 | 1.1754944e-38 | 2^−23 | 9 |
| binary64 (double) | 64 (1, 11, 52) | 1023 | 1.7976931348623157e+308 | 2.2250738585072014e-308 | 2^−52 | 17 |
FAQ
- How do you convert a decimal number to IEEE 754?
- Write the value as 1.f × 2^e, store e + bias in the exponent (bias 127 for float, 1023 for double) and f, rounded to nearest with ties to even, in the fraction. For 0.1 as a float: 0.1 = 1.6 × 2^−4, exponent 123 (0b01111011), fraction 0x4CCCCD, giving 0x3DCCCCCD. The calculator rounds from the exact decimal fraction, not through a double, which avoids double rounding for half and bfloat16.
- Why does 0.1 + 0.2 not equal 0.3?
- None of the three numbers is exact in binary. As a double, 0.1 is stored as 0.1000000000000000055511151231257827..., 0.2 and 0.3 are rounded too, and the rounded sum lands on the double next to 0.3: it prints as 0.30000000000000004. Compare floats with a relative tolerance, never with ==.
- How many digits do you need to print a float without loss?
- 9 significant digits always read back to the same float bits (FLT_DECIMAL_DIG), 17 for a double, 5 for a half and 4 for a bfloat16. So printf("%.9g") on a float is safe. The calculator also shows the shortest decimal that reads back to the same bits, which is often much shorter.
- What is the difference between half (binary16) and bfloat16?
- Both are 16 bits. binary16 has 5 exponent bits and 10 fraction bits: about 3 decimal digits, but a range that stops at 65504. bfloat16 keeps the float's 8 exponent bits and only 7 fraction bits: the same range as a float, about 2 to 3 digits. It is a truncated float, which is why machine learning hardware uses it.
- In what order are the bytes of a float stored?
- On a Cortex-M, x86 or RISC-V, little-endian: 0.1f (0x3DCCCCCD) occupies the bytes CD CC CC 3D. In a network frame or from a big-endian sensor, the order is 3D CC CC CD. The calculator gives both orders and a C array ready to paste into a unit test or a serial protocol.
- What is a subnormal number?
- When the stored exponent is 0, the hidden bit becomes 0 and the exponent stays at its minimum: precision is lost, but values go below the smallest normal. In a float the smallest subnormal is 2^−149, about 1.4e-45. On some processors subnormal arithmetic is much slower, or flushed to zero (flush-to-zero mode).
An electronics design house based in Montpellier, France, AESTECHNO brings 10+ years of hardware and firmware design experience and a 100% success rate on CE/FCC certifications. Encoding follows IEEE 754-2019 (round to nearest, ties to even), computed with exact integers.