IEEE 754 Float Converter — decimal, hex and bit fields

Convert between decimal, hex and binary float32/float64, with the sign, exponent and mantissa fields broken out.

Example: 3.14 as float32 is 0x4048F5C3 — sign 0, exponent 128 (1), normal.

Check it against real silicon

Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.

Chiprun docs

Formula

value = (−1)^sign × 1.mantissa × 2^(exponent − bias)

Calculations follow IEEE 754-2019.

Worked example

3.14 as float32 is 0x4048F5C3 — sign 0, exponent 128 (1), normal.

  1. bit layout

    1 sign + 8 exponent + 23 mantissa = 32 bits

    0 10000000 10010001111010111000011

  2. unbiased exponent = raw − bias

    128 − 127

    1

    The bias lets a plain unsigned field represent negative exponents.

  3. value = (−1)^sign × 1.mantissa × 2^exponent

    (−1)^0 × 1.10010001111010111000011 × 2^1

    3.140000104904175

Frequently asked questions

Why is 0.1 + 0.2 not exactly 0.3?

Because 0.1 and 0.2 have no exact binary representation, in the same way 1/3 has no exact decimal one. Each is stored as the nearest representable value, and the small errors accumulate. Convert 0.1 above to see the stored value differ from what you typed.

What is 0x3F800000?

The float32 encoding of 1.0 — sign 0, exponent 127 (unbiased 0), mantissa all zeros, giving 1.0 × 2⁰. It is worth memorising, because seeing it in a memory dump immediately tells you that you are looking at floats.

What is the difference between float32 and float64?

float32 uses 8 exponent bits and 23 mantissa bits for roughly 7 decimal digits of precision; float64 uses 11 and 52 for about 16. On a microcontroller without a double-precision FPU, float64 arithmetic is emulated in software and dramatically slower.

Why does NaN not equal itself?

The standard defines it that way, so that any comparison involving NaN is false. It gives you a reliable test — x !== x is true only for NaN — and it is why sorting an array containing NaN produces unpredictable order.

Related tools