1from struct import pack2pack('>e', 6.25).hex()3pack('>e', 0.1).hex()40.1 + 0.25(6.25).hex()6250010101010101010101010101010101014211/21/4
Digit cells: the place value on top, the binary digit below; the dot is the binary pointBit lamps: a lit lamp is a 1, a dark lamp a 0Field boards: sign (1 bit), exponent (5 bits), fraction (10 bits), each with its value platePython card: struct.pack and float.hex show the stored bits6.25 stored as a 16-bit half-precision float. The digit row spells 110.01 in binary; the point slides left two places to make 1.1001 × 2². The sixteen bit lamps hold three fields: sign 0, exponent 10001 (2 plus the bias 15 = 17) and fraction 1001000000 (the digits after the point; the leading 1 is not stored). Then 0.1, whose binary digits never end, is cut to ten fraction bits and rounded to 0.0999755859375.

Moving the point

  1. Scientists write 6250 as 6.25 × 10³: a few digits, times a power of ten. The power says where the decimal point goes. A floating-point number works the same way, but in base 2. Our example is 6.25.

Packing the bits

Rounding

In Python

Try it in the Python prompt

;; step 1/11 · Scientific notation
>>> 6.25e3                   # 6.25 × 10**3
6250.0
>>> 6250 / 10**3
6.25

IEEE 754 defines the common formats. Half precision (binary16) has 1 sign, 5 exponent and 10 fraction bits, bias 15. Single (binary32) has 1, 8 and 23, bias 127. Double (binary64), Python's float, has 1, 11 and 52, bias 1023. Two exponent patterns are reserved. All 0s means zero or a tiny "subnormal" number with no hidden 1; all 1s means infinity or NaN (not a number). That is why half-precision exponents run only from −14 to +15.