IEEE 754 Notation

3. Creating the Bitstring

You're almost done when the number is in this form:

(-1)sign bit  *  (1+fraction)  *  2exponent - bias

This was a clever move. Instead of one messy value, you now have three important pieces of information that can identify the number.

• If the sign bit is a 0, then the number is positive; (-1)0 = 1. If the sign bit is a 1, the number is negative.

• We always factor so that the number in parentheses equals 1 + some fraction. Since we know that the 1 is there, the only important thing is the fraction, which you will write as a binary string. Just multiply each digit times its place value, as in these examples:

0.1bin = 2-1 = (1/2)
0.01bin = 2-2 = (1/4)
0.101bin = 2-1 + 2-3 = (5/8)

• The power of 2 that you got in the last step is simply an integer. Since you don't want to deal with any messy negative numbers, you can add a constant value (the bias) to that power.

For single-precision floating-point, the bias=127.
For double-precision, the bias=1023.

The sum of the bias and the power of 2 is the exponent that actually goes into the IEEE 754 string. Remember, the exponent = power + bias. (Alternatively, the power = exponent-bias).

When you have calculated these binary values, you can put them into a 32- or 64-bit field. The digits are arranged like this:

Single precision (32-bit) form: (Bias = 127)
 (1)sign (8) exponent (23) fraction

Double precision (64-bit) form: (Bias = 1023)
 (1)sign (11) exponent (52) fraction

The numbers in parentheses show how many bits are required in each field.

Example: Float to IEEE 754 ->