5 / 24 · Concept
Fixed-point bits and units
Multiply 0.5 and −1.25 at F=4, then add bias 0.25 at F=8. What are accumulator code and real value?
Lessons are free to read. Enroll to save your learning progress.
Attach a unit to the integer
Fixed-point represents a real value using an integer code and a fixed scale. We specify eight total bits, two's-complement signed storage and four fractional bits, F=4. A code q represents q×2⁻⁴. Q-format naming conventions can disagree about whether the sign counts as an integer bit, so write total width, signedness and F explicitly. The codes −128 through 127 represent −8 through 7.9375.
The same bit pattern changes meaning with its scale. Code 24 represents 1.5 at F=4 but three at F=3. Adding codes with different units is wrong even with a wide adder. Align scales first and define any rounding and overflow that alignment introduces.
Worked example
Encode 1.5 as 24 and −0.75 as −12. The integer product is −288. Fractional widths add, so the product has F=8 and represents −288/256=−1.125. Two signed eight-bit operands fit their full product in sixteen bits, but a sum of many products needs a separate accumulator-width calculation. Rounding every product back to F=4 introduces an error on every term. Our contract preserves the product scale through accumulation and rounds once at the output.
A real bias of 0.5 becomes code 128 at F=8. Adding it gives −160, representing −0.625. Adding code eight, which is the bias at F=4, would use the wrong unit. Document bias scale alongside its stored code.
When widening a negative two's-complement code, replicate the sign bit. The eight-bit representation of −12 is 11110100; its sixteen-bit extension is 1111111111110100. Zero extension changes it to positive 244. Declare RTL operands and intermediates signed, and make their widths explicit rather than assuming a narrow destination fixes expression sizing.
Power-of-two scales make the shift relationship easy to inspect. General affine quantization uses other positive scales and a zero point. Keep code, scale and represented value together in your design notes so that multiplication, accumulation and final conversion remain understandable.
Try it yourself
Multiply 0.5 and −1.25 at F=4, then add bias 0.25 at F=8. What are accumulator code and real value?
Read the explanation
Codes are eight and −20, giving product −160. Bias code is 64. Accumulator −96 at F=8 represents −0.375.