Edexcel International Advanced Level Computer Science, point 2.1.4
Definition
Fixed-point representation stores a number with a fractional part using a fixed number of bits for the whole part and a fixed number for the fractional part. The binary point is in the same place for every number, and isn't stored. The sign uses two's complement (2.1.3), so the MSB has a negative place value.
Function and why needed
Computers need to store numbers like 5.75 or −0.125. Fixed point does this with the same circuits as whole-number arithmetic, which is simple and fast. It's used when the range and precision are known in advance (for example money, audio samples and small embedded devices).
Characteristics
Place values
After the binary point, the place values are fractions that halve each time:
| ... | 4 | 2 | 1 | . | ||||
|---|---|---|---|---|---|---|---|---|
| 0.5 | 0.25 | 0.125 | 0.0625 |
You need to work with halves, quarters and eighths (and sometimes sixteenths). Most examples here use 5 whole bits and 3 fraction bits, but a question can use any split, so always look for where the point is.
An 8-bit format: 5 whole bits and 3 fractional bits
- The MSB (b7) is worth −16.
- The smallest step (precision) is .
- Range: −16 to (that is ).
In general, with integer bits (including the sign) and fractional bits:
Operation
Fixed-point binary to denary
00101.110:
11010.010:
Denary to fixed-point binary (positive)
Convert the whole part and the fraction separately.
3.625: whole part . Fraction , so bits 101. Result: 00011.101.
To convert a fraction, repeatedly subtract the largest of 0.5, 0.25, 0.125 that fits, or multiply by 2 and take the whole-number part each time:
| Step | Calculation | Bit |
|---|---|---|
| 0.625 × 2 | 1.25 | 1 |
| 0.25 × 2 | 0.5 | 0 |
| 0.5 × 2 | 1.0 | 1 |
Denary to fixed-point binary (negative)
Use two's complement: write the positive value, invert all bits (including the fraction bits) and add 1 to the least significant bit.
−5.75:
-
00101.110 - Invert:
11010.001 - Add (the last bit):
11010.010
Check: . ✓
Reading any format
A question may use a different number of bits, or a different split, and may not give the place values. Work them out from the position of the point:
- The bit just left of the point is worth 1, and each bit further left is double.
- The leftmost bit (the sign bit) is negative: with whole bits it is worth .
- The bits right of the point are worth , , , , and so on.
Example: a 10-bit number with 6 whole bits and 4 fraction bits: 110100.1100.
| 16 | 8 | 4 | 2 | 1 | . | |||||
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 0 | 0 | . | 1 | 1 | 0 | 0 |
Range against precision
For a fixed total number of bits, there is a trade-off:
| More fraction bits | More whole bits |
|---|---|
| Finer precision (smaller steps) | Larger range |
| Smaller range | Coarser steps |
With 8 bits: 4 whole and 4 fractional gives a range of to with a step of . 5 and 3 gives a range of to with a step of .
Benefits and drawbacks
- Benefits: fast and simple (integer hardware), no rounding surprises for a fixed step (good for money in pence), uses little memory.
- Drawbacks:
- A limited range and limited precision.
- Values that aren't an exact multiple of the step can't be stored exactly: has no exact binary fraction, so it is rounded (a rounding error).
- Overflow if a result is too large.
- The point is fixed when the system is designed, so needing a bigger range or finer precision means redesigning it. Bits can be wasted: a system built for large whole numbers has fewer bits left for the fraction.
- The nearest value may be all you can store: with 3 fraction bits, 0.3 can only be stored as 0.25 (
.010). - Floating point (11.3.1) is more flexible, at the cost of speed and complexity.
Worked example
Task: using 8 bits (5 whole, 3 fractional, two's complement), (a) store −2.375, and (b) find the largest and smallest values and the step.
(a)
- , so
00010.011. - Invert:
11101.100. - Add :
11101.101.
Check: . ✓
(b)
- Smallest:
10000.000. - Largest:
01111.111. - Step: .
Exam tip: mark the binary point in your answer, and say how many bits are on each side. For negatives, invert, then add 1 at the very last bit, not at the binary point. Always check by adding the place values (with the MSB negative). If a number can't be stored exactly, say it is rounded and what the step size is. If no place values are given, work them out from where the point is (the sign bit is negative). An answer can be a fraction, but write it clearly: , not 225/8.
Check yourself
What is the value of 00011.110 in a format with 3 fractional bits?
2 + 1 + 0.5 + 0.25 = 3.75.
What is the smallest difference between two numbers in a format with 3 fractional bits?
1/8 = 0.125.
How does the trade-off work between whole bits and fractional bits?
For a fixed total number of bits, more fractional bits give finer precision but a smaller range, and more whole bits give a larger range but coarser precision.
Why can't 0.1 be stored exactly in fixed-point binary?
It is not a sum of halves, quarters, eighths and so on, so it can only be approximated, which causes a rounding error.
How is a negative fixed-point number formed?
Write the positive number, invert all the bits, and add 1 to the least significant bit (two's complement).