OCR H446, section 1.4.1 (g)
Integers are easy to store, but real numbers (with fractional parts, and very large or very small values) are harder. Floating point form stores a number in two parts, like scientific notation.
In denary, can be written as . In binary floating point, the base is 2:
- The mantissa holds the significant digits of the number, and its sign.
- The exponent says how many places the binary point moves (it "floats"), and so the scale of the number.
The format used here
In exam questions, the sizes are given. These examples use an 8-bit mantissa and a 4-bit exponent, with both in two's complement.
- The mantissa is a fixed point number with the binary point after the first bit. The first bit is the sign bit, worth . The bits after the point are worth , , , and so on. So the mantissa is .
- The exponent is a 4-bit two's complement integer, from to .
From floating point to denary
- Work out the mantissa as a number between and just under .
- Work out the exponent (a two's complement integer).
- Multiply: mantissa .
Example 1: mantissa , exponent .
- Mantissa: .
- Exponent: .
- Value: .
In effect, the exponent moves the binary point 3 places right: . A negative exponent moves it left.
Example 2 (negative mantissa): mantissa , exponent .
- Mantissa: the sign bit is worth , so .
- Exponent: .
- Value: .
From denary to floating point
- Convert the number (its magnitude) to binary, including the fractional part.
- Move the binary point so that the mantissa starts (for a positive number). Count the places moved: this gives the exponent.
- Write the mantissa in the available bits, and the exponent in two's complement.
- If the number is negative, take the two's complement of the positive mantissa.
Example: represent 6.25.
- ().
- Move the point 3 places left: .
- Mantissa (8 bits): . Exponent: .
- Check: , and . ✓
Example: represent .
- Take the positive mantissa , and find its two's complement: invert to , then add 1 to get .
- Exponent: (the same).
- Check: , and . ✓
Usually the exponent doesn't change when a number becomes negative. Only the mantissa does. But watch out for the exception below.
Watch out: negative powers of two. Represent . Using the method above, , and the two's complement of the mantissa is . That starts , so it isn't normalised. Shift it left one place to (which is ) and reduce the exponent to . Check: . ✓
Another method for negative numbers: write the negative number in two's complement fixed point first, then move the point. For : , so (invert and add 1 in the last place; check: ). Move the point 3 places left to get : mantissa , exponent . Check: . ✓ Either method is fine in the exam.
Example: a small number, 0.1875.
- ().
- Move the point 2 places right to get , so the exponent is negative.
- Mantissa: . Exponent: in 4-bit two's complement is .
- Check: . ✓
Normalisation
The same number can be written in many floating point forms. For example, 6.25 can be:
| Mantissa | Exponent | Value |
|---|---|---|
| (3) | ||
| (4) | ||
| (5) |
Only the first uses all the mantissa bits well. Normalisation is putting the number in the standard form.
When is a number normalised?
The first two bits of the mantissa are different.
| Number | Normalised mantissa starts | Mantissa value |
|---|---|---|
| Positive | from up to just under | |
| Negative | from up to just below (more negative than ) |
A positive mantissa starting , or a negative one starting , isn't normalised: there is a wasted bit at the start.
Why normalise?
- Maximum precision. All the mantissa bits carry useful digits, instead of being wasted on leading zeros (or ones).
- A unique representation. Each number has only one normalised form, which makes comparing numbers easier.
- Simpler arithmetic, as the numbers are in a standard form.
How to normalise
Shift the mantissa left until the first two bits differ, and reduce the exponent by 1 for each shift (shifting left doubles the mantissa, so the exponent must compensate).
Positive example: mantissa , exponent (value ).
- Shift left 2 places: .
- Exponent: .
- Result: mantissa , exponent . The value is still . ✓
Negative example: mantissa , exponent .
- Value: , and .
- Shift left 3 places (the first two bits must become ): , so .
- Exponent: .
- Check: , and . ✓
Zeros are shifted in at the right. The leading 1s that move out of a negative number were only copies of the sign bit, so the value doesn't change.
Precision and range
The total number of bits is fixed, so the designer must decide how to share them between the mantissa and the exponent.
| More bits for the | Gives | Because |
|---|---|---|
| Mantissa | More precision (accuracy) | More significant digits can be stored |
| Exponent | A larger range | The point can move further, so much larger and much smaller numbers fit |
With a fixed total, more of one means less of the other: more precision means a smaller range, and a larger range means less precision.
Worked example
Task: store 10.5 as a normalised floating point number (8-bit mantissa, 4-bit exponent), and give the value .
- .
- Move the point 4 places left: .
- Mantissa (starts , so normalised), exponent .
- Check: . ✓
- For : two's complement of . Invert: . Add 1: . Exponent . (Check: , and . ✓ It is normalised, as it starts .)
Exam tip: the test for normalisation is that the first two bits of the mantissa differ. When you shift the mantissa left, reduce the exponent. Always check by converting back to denary. State clearly the sign of the mantissa and the value of the exponent.
Check yourself
What are the two parts of a floating point number?
The mantissa, which holds the significant digits and the sign, and the exponent, which sets where the binary point is.
What is the value of mantissa 0.1100000 with exponent 0010?
The mantissa is 0.75, the exponent is 2, so the value is .
How can you tell that a floating point number is normalised?
The first two bits of the mantissa are different: it starts 0.1 if positive, or 1.0 if negative.
Why are floating point numbers normalised?
It gives the maximum precision (no bits wasted), and each number has a unique representation.