loot.tools

IEEE 754 Float Converter

Type a decimal number and watch it broken down into the exact bits a computer stores. The converter shows the sign, exponent, and mantissa for both 32-bit (float) and 64-bit (double) IEEE 754, the hex word you'd see in a memory dump, and the value that actually gets stored after rounding - which is how you finally see why 0.1 isn't 0.1. Go the other way too: paste a hex bit pattern and get the number back. It flags zeros, subnormals, infinities, and NaN, and runs entirely in your browser.

See exactly how a number is stored in memory as an IEEE 754 floating-point value. Enter a decimal number or a raw hex pattern and get the sign, exponent, and mantissa bits, the hex word, and the rounding error the format introduces. This is why 0.1 isn't really 0.1.

Normal32-bit IEEE 754, exponent bias 127
Hex (big-endian)
3dcccccd
Stored value
0.10000000149011612
Rounding error: 1.4901e-9
Bit layout
0 0111 1011 1001 1001 1001 1001 1001 101
Sign
0 (+)
Exponent (8 bits)
raw 123, 2^-4
Mantissa (23 bits)
10011001100110011001101

How a float is built from bits

An IEEE 754 number packs three pieces into a fixed set of bits: one sign bit, a block of exponent bits, and the rest as the mantissa (the fraction). A 32-bit float uses 1 + 8 + 23 bits; a 64-bit double uses 1 + 11 + 52. The stored value is roughly the mantissa times two to the exponent, with the exponent offset by a bias (127 for float, 1023 for double). This tool colors each section so you can see where one ends and the next begins.

Why 0.1 isn't really 0.1

Numbers like 0.1 or 0.2 have no exact binary fraction, the same way 1/3 has no exact decimal. The format rounds to the nearest value it can represent, so what gets stored is a hair off. Enter 0.1 and the 'stored value' row shows 0.10000000149... in 32-bit, along with the tiny rounding error. That stored difference is the whole reason 0.1 + 0.2 doesn't equal 0.3 in almost every programming language.

What the special cases mean

  • All-zero exponent and mantissa is a signed zero
  • All-zero exponent with a nonzero mantissa is a subnormal, used for values too small for the normal range
  • An all-ones exponent with a zero mantissa is infinity
  • An all-ones exponent with a nonzero mantissa is NaN
  • The converter labels each of these so you know exactly which case a bit pattern lands in