4.5.4.4 - Fixed-point and floating-point representation
You will encode and decode binary values with fractional parts using fixed point and a simplified mantissa-and-exponent format. The format must state the bit allocation and binary-point position before any pattern has a definite value.
Binary fractional place values
To the right of a binary point, each position has half the weight of the position immediately to its left.
The first four fractional weights are , , and . Thus , while . A binary point serves the same positional purpose as a decimal point but separates powers of two.
For decimal to binary, split the integer and fractional parts. To encode , the integer part 3 is . The fraction 0.375 is , giving fractional bits .011 and therefore .
Repeated doubling is another way to find fractional bits. Double 0.375 to get 0.75: record integer part 0. Double the remainder 0.75 to get 1.5: record 1 and retain 0.5. Double 0.5 to get 1.0: record 1 and retain zero. Read these bits in their generated order to obtain .011. Unlike integer division remainders, fractional doubling bits are not reversed.
Trailing fractional zeros do not change a value, so . However, a limited number of fractional places may prevent an exact encoding; this is examined in the error lesson.
Signed fixed-point values
Fixed point reserves the same number of fractional positions for every value in the format.
A fixed-point format has an agreed binary-point position. The point is normally implied, rather than stored as an extra bit. For an eight-bit signed format with four fractional bits, the weights are . The first four stored bits are before the implied point, including the sign bit.
The pattern represents . The stored eight bits are 01010110. To encode , first encode as 00110100, then invert all eight bits and add one: 11001011 becomes 11001100. With the point restored, . Negate the whole fixed-width pattern, including fractional bits.
An equivalent method is to multiply by the scale factor before encoding. With four fractional bits, multiply by : , whose eight-bit two's-complement pattern is 11001100. Decode by treating the pattern as a signed integer and dividing by 16.
With signed bits and fractional bits, fixed-point values are signed integers scaled by . Spacing is ; range is to .
For the eight-bit/four-fractional-bit format, spacing is 0.0625 and the range is to 7.9375. More fractional bits improve resolution but leave fewer bits for large integer magnitudes. An unsigned fixed-point task instead uses a positive leading weight; the task must specify the interpretation.
Mantissas and signed exponents
Floating point separates a fractional value from a power-of-two scale, allowing the effective binary-point position to vary.
A simplified binary floating-point value is , where is the mantissa and is the exponent.
This course uses the examined simplified representation, rather than the IEEE standard. Both fields use two's complement. State the split: in a six-bit mantissa/four-bit exponent format there are ten stored bits. The mantissa's implied point is immediately after its sign bit, so its weights are . The exponent is a signed integer with weights .
To decode mantissa 010101 and exponent 0011, calculate and . Therefore . Do not read the exponent as an unsigned value, or multiply by the exponent itself.
For mantissa 011000 and exponent 1110, and , so . A negative exponent makes the scale smaller; it does not make the value negative. The mantissa determines the sign of the value.
For mantissa 101011 and exponent 0011, . With , . The negative mantissa is a two's-complement fraction, not a sign bit followed by an unsigned magnitude.
Encoding signed fractional values
To encode a decimal value, choose a power-of-two scale that leaves its significant digits within the available mantissa positions.
For , first write . Moving the point three places left gives . In the six-bit mantissa/four-bit exponent format, the mantissa is 011010, including the leading sign bit and a trailing zero; exponent 3 is 0011. The complete fields are therefore 011010 and 0011. Decode them to check: .
To encode , negate the complete mantissa: 011010 becomes 100101 after inversion, then 100110 after adding one. Keep exponent 0011. The mantissa now equals , and . Do not negate the exponent when negating the value.
A small positive value may require a negative exponent. For , write , giving mantissa 011000 and exponent 1111. Its exact value fits the six mantissa bits. The floating-point limits lesson explains how to choose a normalised representation and why leading redundant sign bits waste precision.
Always count sign bits within the specified allocation. If the value needs more significant fractional bits than the mantissa contains, an approximation is necessary; if the exponent cannot hold the required scale, changing the mantissa alone does not guarantee that the value can be stored.
Decode each field separately before applying . For encoding, preserve the value when moving the point, then encode both signed fields at the requested widths.