Normalise floating-point numbers
13.3 Floating‑point numbers, representation and manipulation
What is a floating‑point number?
A floating‑point number is like a decimal number that can grow or shrink its “decimal point” (the exponent) so that we can represent very large or very small values with a fixed number of bits. Think of it as a phone number that can be written in a short form: +1 (555) 123‑4567 → +15551234567 – the format stays the same, but the value is the same.
IEEE‑754 format (simplified)
Most computers use the IEEE‑754 standard. A 32‑bit single‑precision number is split into three parts:
| Bits | Meaning |
|---|---|
| 1 | Sign bit (0 = positive, 1 = negative) |
| 8 | Exponent (biased by 127) |
| 23 | Mantissa (fractional part) |
Why do we need normalisation?
Normalisation ensures that the mantissa starts with a leading 1 (for normal numbers). This gives us the most precision for the value we can store. If we didn’t normalise, we could lose significant digits.
Normalisation process (step‑by‑step)
- Write the number in binary scientific notation. Example: $-13.375_{10} = -1101.011_{2}$
- Shift the binary point so that there is exactly one non‑zero digit to the left. $-1101.011_{2} = -1.101011 \times 2^{3}$
- Record the sign bit. Sign = 1 (because the number is negative)
- Calculate the exponent. Exponent = 3 (from the shift) Stored exponent = $3 + 127 = 130$ → binary $10000010$
- Store the mantissa. Drop the leading 1 (it’s implicit) and keep the next 23 bits: $10101100000000000000000$
- Combine the parts.
Final 32‑bit pattern:
1 10000010 10101100000000000000000
Illustrative example
Let’s normalise $0.00015625_{10}$.
- Binary: $0.00015625 = 0.000001010000_{2}$
- Shift to get one 1 left of the point: $1.010000 \times 2^{-4}$
- Sign bit: 0 (positive)
- Exponent: $-4 + 127 = 123$ → binary $01111011$
- Mantissa: drop leading 1 → $01000000000000000000000$
- Resulting 32‑bit pattern:
0 01111011 01000000000000000000000
Common pitfalls
- Underflow. Numbers too small to be normalised become denormalised or zero.
- Overflow. Numbers too large cannot be represented and become infinity.
- Rounding errors. When the mantissa is truncated, the value may be slightly off.
Quick practice
Try normalising the following numbers. Write down the sign bit, exponent, and mantissa.
- $5.25_{10}$
- $-0.75_{10}$
- $1024_{10}$
Take‑away
Normalising a floating‑point number is like adjusting a camera lens: you zoom in until the main subject (the leading 1) is clear, then record the zoom level (the exponent) and the details (the mantissa). This keeps the picture sharp across a huge range of values.
Revision
Log in to practice.