1.4.1 - Floating-point representation and normalisation

1.4.1 - Floating-point representation and normalisation

The same fixed collection of bits can represent a small fraction or a large value if a separate exponent scales it. This part of 1.4.1 builds binary fractions, interprets signed mantissas and exponents, and normalises positive and negative floating-point values. Every calculation states its format so you can tell the stored pattern from the number it represents.

Binary fractions and fixed-point weights

The weights to the right of a binary point are 2−1,2−2,2−3,…2^{-1},2^{-2},2^{-3},\ldots: one half, one quarter, one eighth and so on. An unsigned binary fraction 0.1011 therefore means 1/2+1/8+1/16=0.68751/2+1/8+1/16=0.6875. The point marks the boundary between whole-number and fractional weights; it is not a stored bit.

In fixed point, that boundary is agreed in advance. For an eight-bit two's-complement fraction with the binary point immediately after the sign bit, the weights are:

Bit position, left to right12345678
Weight-11/21/41/81/161/321/641/128

Thus 01011000, interpreted as 0.1011000, is +0.6875. 10101000, interpreted as 1.0101000, is −1+1/4+1/16=−0.6875-1+1/4+1/16=-0.6875. Inversion plus one of the complete eight-bit positive pattern also produces that negative pattern. The range is -1 through +127/128, and the spacing between consecutive values is 1/128. Do not read 10101000 using integer weights -128, 64, 32 and so on when this fractional point has been specified.

To convert a terminating denary fraction to binary, select fractional weights. For 0.3125, use 1/4 and 1/16: 0.0101. Alternatively, repeatedly multiply the fractional remainder by two and take each whole-number digit in order: 0.3125 × 2 = 0.625 gives 0; 0.625 × 2 = 1.25 gives 1 and remainder 0.25; 0.25 × 2 = 0.5 gives 0; 0.5 × 2 = 1 gives 1 and remainder zero. This produces the same digits 0101.

A signed mantissa scaled by a signed exponent

A floating-point format separates significant digits from their scale.

Binary floating-point value

A binary floating-point value has a mantissa and exponent. In the format used here, the mantissa is a two's-complement fraction with its point immediately after the sign bit, and the exponent is a two's-complement integer.

The two fields combine as follows:

value=mantissa×2exponent.\text{value} = \text{mantissa}\times 2^{\text{exponent}}.

The mantissa supplies the significant binary digits; the exponent supplies their scale. A positive exponent multiplies by a power of two, while a negative exponent divides by a power of two. The exponent's sign does not determine the value's sign: a negative mantissa with a negative exponent still represents a negative value.

This lesson uses eight mantissa bits and four exponent bits, in that order. The four-bit exponent ranges from -8 (1000) to +7 (0111). The point is implicit after mantissa bit 1; it does not separate the mantissa from the exponent. For example, 01101000 0011 has mantissa 0.1101000 = 0.8125 and exponent 0011 = 3. Its value is 0.8125×23=6.50.8125\times 2^3=6.5.

The representation is an educational signed-mantissa format, not a claim that a Python float uses these fields or that it is IEEE 754. A question's stated field widths and point convention control its interpretation. Decode the two fields separately before combining them; treating all twelve bits as a single integer loses their meaning.

Decode positive and negative floating-point values

Decoding a value is a sequence of two signed interpretations followed by scaling. For 10011000 0011, the mantissa is −1+1/8+1/16=−0.8125-1+1/8+1/16=-0.8125; the exponent is +3. Therefore the value is −0.8125×8=−6.5-0.8125\times8=-6.5. A leading mantissa 1 is not a sign-and-magnitude flag: its -1 weight is part of the sum.

For 01100000 1110, the mantissa is 1/2+1/4=0.751/2+1/4=0.75. The four-bit exponent is −8+4+2=−2-8+4+2=-2, so the value is 0.75×2−2=0.18750.75\times2^{-2}=0.1875. A check by moving the binary point two positions left gives 0.0011, also 1/8+1/161/8+1/16.

For 10110000 1111, the mantissa is −1+1/4+1/8=−0.625-1+1/4+1/8=-0.625, and the exponent is -1. The value is −0.625×1/2=−0.3125-0.625\times1/2=-0.3125. The negative exponent reduces the magnitude; it does not reverse the sign.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account