AQA 7517, section 4.5.4.4
Whole numbers are easy to store, but many quantities have a fractional part, such as 3.75 or 0.1. Binary can show fractions by continuing the place values past the binary point, with each place worth half the one before.
| 8 | 4 | 2 | 1 | . | ||||
|---|---|---|---|---|---|---|---|---|
| . | 0.5 | 0.25 | 0.125 | 0.0625 |
Two ways of storing these in a fixed number of bits are fixed point and floating point.
Fixed point
In fixed point form, the binary point is at a fixed position that is agreed in advance. Some bits are before the point and some after it.
With 8 bits, 4 before and 4 after the point:
| 8 | 4 | 2 | 1 | . | ||||
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 0 | . | 1 | 1 | 0 | 0 |
Decimal to fixed point
Convert the whole and fractional parts separately.
Convert 5.625 to fixed point (4 bits before and 4 after the point).
- Whole part: .
- Fractional part: , so the bits are : 1, : 0, : 1, : 0.
A quick method for the fractional part is to multiply by 2 repeatedly and take the whole-number part each time: (bit 1), (bit 0), (bit 1).
Binary to decimal
Add up the place values, as above.
Floating point
In floating point form, the number is stored in two parts, like scientific notation:
- The mantissa holds the digits of the number (the significant bits).
- The exponent says where the binary point goes, by how many places it moves (it "floats").
You aren't required to know the IEEE standard. You need to understand and use a simplified floating point format with a mantissa and an exponent. In exam questions, both are in two's complement.
The format used here
For the examples we use an 8-bit mantissa and a 4-bit exponent. The mantissa is a two's complement number with the binary point after the first (sign) bit:
The place values of the mantissa bits, from left to right, are , , , , , , and . So the first bit is the sign bit, and the largest positive mantissa is , which is just under 1.
The exponent is a 4-bit two's complement integer, from to .
Floating point to decimal
Mantissa , exponent :
- Mantissa: .
- Exponent: .
- Value: .
In effect, the exponent moves the binary point 3 places right: .
Negative mantissa , exponent :
- Mantissa: .
- Exponent: .
- Value: .
Decimal to floating point
Convert 10.5.
- Write in binary: .
- Move the binary point to just after the first digit, so it reads . That moved the point 4 places left, so the exponent is .
- Mantissa: (padded to 8 bits). Exponent: .
Check: , and . ✓
Convert .
- . Mantissa for : , exponent .
- For , make the mantissa negative using two's complement: invert to get , then add 1 to get .
So is mantissa , exponent , which matches the example above.
Fixed point and floating point compared
| Fixed point | Floating point | |
|---|---|---|
| Binary point | At a fixed position | Moves, set by the exponent |
| Range | Small for the number of bits | Much larger |
| Precision | The same for every number | Varies, so small numbers are very precise |
| Arithmetic | Simple and fast | More complex and slower |
These are discussed further in 4.5.4.7.
Worked example
Task: (a) convert (4 bits after the point) to decimal. (b) Convert 2.75 to fixed point with 4 bits before and 4 after.
- (a) .
- (b) , and , so . The answer is .
Exam tip: in a floating point question, work out the mantissa value, then the exponent value, and finally multiply by . When converting from decimal, check your answer by converting it back.
Check yourself
What is in decimal?
.
What does the exponent do in a floating point number?
It sets where the binary point goes, by moving it a number of places left or right, so it multiplies the mantissa by a power of 2.
What is the value of mantissa with exponent ?
Mantissa: . Value: .