Bits, floats, text and encodings

O(1)·O(1) space
Fit

Drag to pan; pinch or Ctrl+scroll to zoom; arrow keys pan once the picture has focus.

0011111111111000000000000000000000000000000000000000000000000000SEEEEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMBitsField
  • Being read

The sign bit is 0, meaning the value is positive or zero.

The sign bit is 0, meaning the value is positive or zero.
  1. 1read the sign bit
  2. 2read the 11-bit exponent field
  3. 3read the 52-bit mantissa field
  4. 4reconstruct the value, using the right formula for this exponent field
Fields read
1

Complexity

BestO(1)
AverageO(1)
WorstO(1)
Extra spaceO(1)
bits touched at n=1 predicts 1; this run took 1.

IEEE 754 decomposition

Every double-precision float is 64 bits: one sign bit, eleven exponent bits, and fifty-two mantissa bits. A normal number reconstructs as (−1)^sign × 1.mantissa × 2^(exponent − 1023) — the leading 1 is implicit and never stored. Four special cases change that formula: an all-zero exponent means either zero (mantissa also zero) or a subnormal (mantissa nonzero, and the leading bit is 0, not 1); an all-ones exponent means either infinity (mantissa zero) or NaN (mantissa nonzero).

When it is the right choice

Whenever "what does this float’s bit pattern actually mean" is the real question — reading a hex dump, debugging a serialisation format, or understanding why +0 and −0 compare equal yet have different bit patterns.

How it works

Worth noticing

Cost

Best
O(1)
Average
O(1)
Worst
O(1)
Extra space
O(1)

Worth comparing

All bits algorithms