Sub topic 7
Fixed-Point Range, Resolution, and Limitations
Assume you know binary place values, signed two’s-complement integers, and basic exponent rules. Fixed-point representation stores a real number as an integer with an implied binary point at a fixed position.
Working Model
If a stored integer is N and F bits represent the fractional part, the decoded value is:
value = N / 2^F
Equivalently, the binary point is placed F positions from the right. For example, with F = 4, the stored integer 13 represents:
13 / 16 = 0.8125
The number of total bits determines the range. The number of fractional bits determines the resolution, which is the smallest distance between adjacent representable values.
Unsigned Fixed-Point
For an unsigned W-bit format with F fractional bits:
- Smallest value:
0 - Largest value:
2^(W-F) - 2^(-F) - Resolution:
2^(-F)
For example, an 8-bit unsigned format with 4 fractional bits has values from 0 through 15.9375, in increments of 0.0625.
Signed Fixed-Point
For a signed two’s-complement format with W total bits and F fractional bits:
- Smallest value:
-2^(W-F-1) - Largest value:
2^(W-F-1) - 2^(-F) - Resolution:
2^(-F)
The sign bit still contributes to the integer range. A common notation is Q(I.F), but conventions differ on whether I includes the sign bit. Always check the convention before calculating a range.
| Format | Total bits | Fraction bits | Range | Resolution |
|---|---|---|---|---|
| Unsigned 8.4 | 8 | 4 | `0` to `15.9375` | `0.0625` |
| Signed 8-bit, F=4 | 8 | 4 | `-8` to `7.9375` | `0.0625` |
| Signed 16-bit, F=8 | 16 | 8 | `-128` to `127.99609375` | `0.00390625` |
Encoding and Quantization
To encode a real number x, multiply it by 2^F and round to an integer:
N = round(x × 2^F)
The rounding error is usually at most half a resolution step when nearest rounding is used. Values outside the format’s range cause overflow. A system may wrap, saturate at the nearest endpoint, or raise an error. Wrapping can produce a completely incorrect sign, so saturation is often safer for measurements and control systems.
W = 8
F = 4
scale = 1 << F
minimum = -(1 << (W - F - 1))
maximum = (1 << (W - F - 1)) - 1 / scale
def encode(x):
if not minimum <= x <= maximum:
raise OverflowError(f"{x} is outside [{minimum}, {maximum}]")
return round(x * scale)
def decode(n):
return n / scale
stored = encode(3.2)
print(stored, decode(stored)) # 51 3.1875Trade-Offs and Limitations
Fixed-point arithmetic is often faster and more predictable than floating-point arithmetic on small embedded processors. It also gives a fixed quantization error. However, every operation requires range analysis.
- Addition requires operands with the same scaling, or one operand must be rescaled.
- Multiplying two
F-fraction-bit values produces a result with2Ffractional bits. - Intermediate products may need extra storage before being shifted back.
- Repeated rounding can accumulate error.
- A single fixed binary point cannot represent both very large and very small values efficiently.
Exercise
A signed 8-bit fixed-point format has 3 fractional bits. What are its range and resolution?
Show answer
The resolution is 2^-3 = 0.125. The range is -2^(8-3-1) = -16 through 16 - 0.125 = 15.875.