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 : one half, one quarter, one eighth and so on. An unsigned binary fraction 0.1011 therefore means . 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 right | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Weight | -1 | 1/2 | 1/4 | 1/8 | 1/16 | 1/32 | 1/64 | 1/128 |
Thus 01011000, interpreted as 0.1011000, is +0.6875. 10101000, interpreted as 1.0101000, is . 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:
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 .
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 ; the exponent is +3. Therefore the value is . 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 . The four-bit exponent is , so the value is . A check by moving the binary point two positions left gives 0.0011, also .
For 10110000 1111, the mantissa is , and the exponent is -1. The value is . 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