IEEE 754 explorer

Convert a number to IEEE 754 step by step, as in the exam question: to binary, normalise, the exponent with its excess and the rounded mantissa, down to hexadecimal. And the other way, from the word to the number. See the value that is really stored and its error, and flip the bits one by one to see what happens. In single, double and half precision, and the old 16-bit format from the exercises. It runs in your browser, on your phone too.

How to use it

  1. Choose the format and the direction: Decimal → IEEE or Hex → decimal.
  2. Type the number (37.6875, -0.15625, 1e-40) or the word in hexadecimal (4216C000). Or pick an example: the stopwatch lap, the exam-style question, the 0.1 that cannot be stored exactly, a denormal or infinity.
  3. Press Step to see each step: the sign, the binary, normalising, the exponent with its excess, the mantissa (and its rounding) and the word in hexadecimal.
  4. Tap any bit of the word to flip it and see the number you get.

What it works out

It uses exact arithmetic, without going through the browser’s own numbers: the number is written in binary, normalised to 1.xxx × 2E, the exponent is stored by adding the excess (127 in single precision) and the mantissa, without the hidden 1, is rounded to the nearest (and on a tie, to even), as the processor does.

It also shows what is really stored, with every digit, the error when storing it and the gap to the next representable number. Checked against Python on 30,000 numbers.

The rules it follows

  • Exponent all 0s: zero or denormal (0.mantissa × 21−excess); exponent all 1s: infinity or NaN.
  • The old 16-bit format (sign, 5-bit exponent in excess 16 and fractional mantissa 0.1xxx) truncates, with or without a hidden bit, as in level 3 of the exercises.
  • Decimals can be typed with a point or a comma.

For the exam

The exam question asks you to convert a number to IEEE 754 single precision in hexadecimal, or the other way round. Do it on paper and compare it here step by step; the challenge below gives you new numbers.