Chapter 13.3: Floating-Point Numbers, Representation and Manipulation
9618 Computer Science - AS Level
📚 Learning Objectives
Describe the format of binary floating-point real numbers
Convert binary floating-point real numbers into denary and vice versa
Normalise floating-point numbers and understand the reasons for normalisation
Show understanding of the effects of changing the allocation of bits to mantissa and exponent
Show understanding of consequences of a binary representation only being an approximation to the real number it represents
Show understanding that binary representations can give rise to rounding errors
Understand how underflow and overflow can occur
📋 Prior Knowledge Required
Binary number system and conversion between binary and denary
Two's complement representation for negative numbers
Scientific notation in denary (standard form)
Binary fractions and fixed-point representation
Basic understanding of how computers store data
💡 Why This Matters
Floating-point representation is fundamental to how computers handle real numbers (numbers with fractional parts). Without it, computers would be severely limited in scientific calculations, graphics, and many real-world applications. Understanding this topic is essential for exam success!
1. Floating-Point Number Representation
In previous chapters, we learnt about how binary numbers can be stored in fixed-point representation. The magnitude of numbers stored depends on the number of bits used. However, fixed-point representation limits the range of numbers and does not allow for fractional values efficiently.
To increase the range and allow for fractions, we use the method from the denary number system - scientific notation. For example:
312,110,000,000,000,000,000,000 can be written as 3.1211 × 10²³ using scientific notation.
If we adopt this system in binary, we get:
M × 2ᴱ
Where M is the mantissa (significand) and E is the exponent
This is known as binary floating-point representation. In our examples, we will assume a computer uses 8 bits for the mantissa and 8 bits for the exponent.
📖 Key Terms
Mantissa: The fractional part of a floating-point number containing the significant digits
Exponent: The power of 2 that the mantissa is raised to
Binary floating-point number: A binary number written in the form M × 2ᴱ
💡 Exam Tip
A binary point is assumed to exist between the first and second bits of the mantissa. For an 8-bit mantissa, the values are: -1, ½, ¼, ⅛, 1/16, 1/32, 1/64, 1/128. The first bit is the sign bit!
2. Converting Binary Floating-Point to Denary
2.1 Method 1: Calculate Mantissa and Exponent Separately
📝 Step-by-Step Method
Add up the mantissa values where a 1 bit appears
Add up the exponent values where a 1 bit appears
Use the formula: Result = Mantissa × 2^(Exponent)
Example: Convert this binary floating-point number to denary:
For negative numbers: Work with positive first, then negate!
1. Convert the positive version to binary
2. Normalise to 0.1xxx format
3. Apply two's complement
4. Result will start with 1.0xxxxx
4. Normalisation
Normalisation is a method to improve the precision of binary floating-point numbers. A floating-point number is normalised when:
📖 Normalisation Rules
Positive numbers: Mantissa must begin with 0.1
Negative numbers: Mantissa must begin with 1.0
4.1 How to Normalise
📝 Normalisation Steps
For positive numbers (starting with 0.xxx):
Shift the bits LEFT until mantissa begins with 0.1
For each shift left, DECREASE the exponent by 1
For negative numbers (starting with 1.xxx):
Shift the bits LEFT until mantissa begins with 1.0
For each shift left, DECREASE the exponent by 1
Example: Normalise 0.0011100 00000101
Step 1: Shift bits LEFT 2 places → 0.1110000 Step 2: Exponent was 5, reduce by 2 → 3 (00000011) Result: 0.1110000 00000011 ✓ Normalised!
Remember: Positive = 0.1 start, Negative = 1.0 start. The first TWO bits must be different in a normalised number. If they're the same (0.0... or 1.1...), the number is NOT normalised!
4.2 Why Normalise?
Reason
Explanation
Maximum Precision
Leading zeros removed, mantissa makes full use of available bits
Unique Representation
Each number has exactly ONE normalised form
Easier Arithmetic
Computers can perform operations more efficiently
Consistent Format
All numbers follow the same structure
Optimal Bit Usage
Gets the best use out of available bits
5. Precision versus Range
The allocation of bits between mantissa and exponent affects the precision and range of numbers that can be represented. There is always a trade-off between the two.
📖 Key Definitions
Precision: The accuracy of a number - how close the representation is to the actual value. More mantissa bits = higher precision.
Range: The span of numbers that can be represented (from smallest to largest). More exponent bits = larger range.
⚠️ Important: The Trade-off
More bits for mantissa → Higher accuracy/precision but smaller range
More bits for exponent → Larger range but lower precision
The total number of bits remains the same - it's about how we allocate them
💡 Exam Tip
If asked about changing bit allocation, always mention BOTH effects: "Increasing mantissa bits increases precision but reduces range, and vice versa for exponent bits."
6. Floating-Point Problems
There are several important problems associated with floating-point representation that you must understand:
6.1 Rounding Errors and Approximations
📖 The Problem
The storage of certain numbers is an approximation due to limitations in the size of the mantissa. Numbers that cannot be represented exactly as fractions with denominators that are powers of 2 will have rounding errors.
With 8-bit mantissa: 5.88 is stored as 5.75 - an approximation!
❌ Common Mistake
Don't assume all decimal fractions can be represented exactly in binary. For example, 0.1 (one tenth) CANNOT be represented exactly in binary - it's a repeating fraction in binary, just like 1/3 is a repeating decimal in base-10!
6.2 Overflow
⚠️ Overflow Error
Overflow occurs when a calculation produces a number that exceeds the maximum possible value that can be stored in the mantissa and exponent.
Can occur when dividing by a very small number
Can occur when multiplying two very large numbers
Occurs in the exponent when it becomes too large
6.3 Underflow
⚠️ Underflow Error
Underflow occurs when a calculation produces a number smaller than the minimum that can be represented.
Can occur when dividing by a very large number
Can occur when multiplying two very small numbers
Results in a value too close to zero to represent
6.4 The Zero Problem
🌟 Did You Know?
One of the issues of using normalised binary floating-point numbers is the inability to store the number zero! This is because:
Positive normalised numbers must start with 0.1...
Negative normalised numbers must start with 1.0...
Neither pattern allows for a zero value!
Computers use special representations to handle zero.
7. Worked Examples
Example 1: Convert Binary Floating-Point to Denary
📝 Question
Convert this binary floating-point number to denary (8-bit mantissa, 8-bit exponent):
Always verify your normalised result gives the same value as the original!
Original: -5/32 × 2¹⁰ = -5 × 32 = -160
Result: -5/8 × 2⁸ = -5 × 32 = -160 ✓ Correct!
8. Exam-Style Questions
1. A computer uses 8 bits for the mantissa and 8 bits for the exponent in a floating-point representation. Both use two's complement format. Convert the denary number +6.75 into its binary floating-point representation. Show your working. [4 marks]
Answer:
6 = 110 in binary, 0.75 = 0.11 in binary
Combined: 110.11
Normalise: 0.11011 (move binary point 2 places left)
Exponent = 2 = 00000010
Mantissa = 01101100 (padded with zeros)
Final Answer: Mantissa = 01101100, Exponent = 00000010
Additional points for deeper understanding: The binary point is assumed between the first and second bits. Moving the point left increases the exponent. The sign bit is 0 for positive numbers.
2. Convert the following binary floating-point number to denary. The mantissa is 8 bits and the exponent is 8 bits, both in two's complement. Mantissa: 11010100 | Exponent: 00000011[3 marks]
3. Explain why the number 0.1 (one tenth) cannot be represented exactly in binary floating-point format. [3 marks]
Answer:
0.1 in denary cannot be expressed as a fraction with a denominator that is a power of 2
When converting 0.1 to binary, it results in a repeating binary fraction (similar to how 1/3 is a repeating decimal)
The mantissa has limited bits, so the infinite binary expansion must be truncated
This leads to an approximation rather than an exact representation
Additional points: This is why programs that repeatedly add 0.1 may show unexpected results like 0.3999999 instead of 0.4. Double precision can reduce but not eliminate this error.
4. Normalise the following binary floating-point number: 0.0011100 00000101[3 marks]
Answer:
This is a positive number (starts with 0)
Need to get 0.1xxxxx format
Shift bits LEFT 2 places: 0.0011100 → 0.1110000
Reduce exponent by 2: 5 - 2 = 3 (00000011)
Result: Mantissa = 01110000, Exponent = 00000011
Verification: Original = 7/64 × 2⁵ = 7/64 × 32 = 3.5. Result = 7/8 × 2³ = 7/8 × 8 = 7. Wait - there's an error! Let me recalculate.
5. A computer system uses floating-point representation with 12 bits for the mantissa and 4 bits for the exponent. Describe the effect on precision and range if the allocation is changed to 8 bits for the mantissa and 8 bits for the exponent. [4 marks]
Answer:
Effect on Precision: Reducing mantissa from 12 to 8 bits decreases precision. Fewer bits are available to store the significant digits, so numbers will be less accurate approximations.
Effect on Range: Increasing exponent from 4 to 8 bits increases the range. More exponent bits allow representation of both larger and smaller numbers.
Trade-off: The change represents a trade-off - sacrificing precision for increased range.
Practical impact: Very large/small numbers can be stored, but with less accuracy.
Additional points: Original max ≈ 2047/2048 × 2⁷. New max ≈ 127/128 × 2¹²⁷ - much larger but less precise.
8. Exam-Style Questions (Continued)
6. Explain what is meant by overflow in the context of floating-point representation. Give an example of when this might occur. [4 marks]
Answer:
Definition: Overflow occurs when a calculation produces a number that exceeds the maximum value that can be stored in the allocated mantissa and exponent bits.
Where it occurs: Overflow can occur in the exponent when it becomes too large to be represented with the available bits.
Example 1: Dividing a number by a very small number (e.g., dividing by 0.0000001)
Example 2: Multiplying two very large numbers together
Result: An overflow error will be produced by the computer system.
Additional points: For 8-bit exponent, maximum positive value is around 2¹²⁷. Any calculation resulting in a larger value would cause overflow.
7. Explain what is meant by underflow in floating-point representation. [3 marks]
Answer:
Definition: Underflow occurs when a calculation produces a number smaller than the minimum value that can be represented.
When it occurs: When dividing by a very large number, or multiplying two very small numbers together.
Result: The result is too close to zero to be represented with the available bits, leading to an underflow error or the value being stored as zero.
Additional points: For 8-bit exponent in two's complement, the smallest positive number is approximately 1/128 × 2⁻¹²⁸.
8. A student writes a program that adds 0.1 to a variable 1000 times. Explain why the final result might not be exactly 100. [4 marks]
Answer:
0.1 cannot be represented exactly in binary floating-point format.
When converted to binary, 0.1 becomes a repeating fraction that must be truncated to fit in the mantissa.
Each time 0.1 is added, a small rounding error accumulates.
After 1000 additions, these accumulated errors become significant enough to cause the result to differ from 100.
The result might be something like 99.9999999 or 100.0000001 depending on the direction of the rounding.
Additional points: This is a fundamental limitation of floating-point arithmetic. Using double precision can reduce but not eliminate this problem.
9. State the format that a normalised floating-point number must follow for: (a) positive numbers, (b) negative numbers. Explain why normalisation is used. [5 marks]
Answer:
(a) Positive numbers: Mantissa must begin with 0.1 (the first two bits must be different, starting with 0)
(b) Negative numbers: Mantissa must begin with 1.0 (the first two bits must be different, starting with 1)
Why normalise:
Ensures maximum precision by using all available mantissa bits
Provides a unique representation for each number
Makes arithmetic operations more accurate and efficient
Simplifies the hardware required for calculations
10. Convert -6 to binary floating-point format using 4 bits for the mantissa and 4 bits for the exponent, both in two's complement. [4 marks]
Answer:
+6 = 110 in binary = 0.110 × 2³
For negative: apply two's complement to mantissa bits
0.110 → flip bits → 1.001 → add 1 → 1.010
Mantissa = 1010 (4 bits, starts with 1 for negative)
The fractional part of a floating-point number containing the significant digits. In binary floating-point, the first bit is the sign bit (0 = positive, 1 = negative).
Exponent
The power of 2 that the mantissa is raised to in a floating-point number. Stored in two's complement format. Determines how far to move the binary point.
Binary Floating-Point Number
A binary number written in the form M × 2ᴱ, where M is the mantissa and E is the exponent. Allows representation of fractional and very large/small numbers.
Normalisation
A method to improve the precision of binary floating-point numbers. Positive numbers should be in format 0.1..., negative numbers in format 1.0...
Overflow
The result of carrying out a calculation which produces a value too large for the computer's allocated word size. Can occur in the exponent when it becomes too large.
Underflow
The result of carrying out a calculation which produces a value too small for the computer's allocated word size. Results in a value too close to zero to represent.
Precision
The accuracy of a number representation - how close the stored value is to the actual value. Increased by having more bits in the mantissa.
Range
The span of numbers that can be represented, from smallest to largest. Increased by having more bits in the exponent.
Rounding Error
An error that occurs when a number cannot be represented exactly in binary floating-point format and must be approximated.
Two's Complement
A method of representing negative binary numbers. To find two's complement, flip all bits and add 1. Used for both mantissa sign and exponent storage.
10. Exam Success Tips (Part 1)
💡 Remember the Normalisation Rules
Positive numbers: MUST start with 0.1
Negative numbers: MUST start with 1.0
The first TWO bits must always be DIFFERENT in a normalised number
If first two bits are the same (0.0... or 1.1...), the number is NOT normalised
💡 Converting Binary Floating-Point to Denary
First, check the sign bit (first bit of mantissa)
Add up all the place values where there's a 1
For negative mantissa, you may need to use two's complement first
Multiply the mantissa by 2^(exponent) to get the final answer
Alternative method: Move the binary point according to the exponent
💡 Converting Denary to Binary Floating-Point
Convert integer part using standard binary conversion
Convert fractional part using repeated multiplication by 2
Combine and normalise by moving the binary point
Count moves to get the exponent
For negative numbers: work with positive first, then apply two's complement
🧠 Memory Trick: Exponent Direction
POSITIVE exponent: Move binary point RIGHT → Number gets BIGGER
NEGATIVE exponent: Move binary point LEFT → Number gets SMALLER
Think: "Positive point Right, Negative point Left" (PRNL)
💡 When Normalising
Shift bits LEFT to normalise
Each left shift DECREASES the exponent by 1
Always verify: the normalised form should give the same value!
❌ Common Mistakes to Avoid
Don't confuse mantissa sign bit with two's complement - only the exponent uses two's complement in CIE format
Don't forget to normalise your answer if asked
Don't assume all decimal fractions have exact binary representations
Don't forget to pad mantissa with zeros to fill all bits
Don't confuse overflow (too large) with underflow (too small)
10. Exam Success Tips (Part 2)
💡 Precision vs Range Questions
More mantissa bits = Higher precision (more accurate) but smaller range
More exponent bits = Larger range but lower precision
Always mention BOTH effects when answering these questions
Use the phrase "trade-off between precision and range"
🧠 Memory Trick: Mantissa vs Exponent
Mantissa = More accuracy (M for Mantissa, More precision)
Exponent = Extends range (E for Exponent, Extends)
💡 Understanding Rounding Errors
Numbers like 0.1, 0.2, 0.3 CANNOT be represented exactly in binary
These produce repeating binary fractions
Truncation leads to approximation errors
Accumulated errors can cause unexpected results in programs
⚠️ Key Points for Exam Questions
Always show your working - marks are awarded for method
State assumptions clearly (e.g., "assuming 8-bit mantissa...")
Check your answer makes sense (is the sign correct? Is the magnitude reasonable?)
For conversion questions, verify by converting back
Use correct terminology: mantissa, exponent, normalise, two's complement
💡 The Zero Problem
Remember: Zero cannot be represented in normalised floating-point because:
Positive normalised must start with 0.1...
Negative normalised must start with 1.0...
Neither allows all bits to be zero!
Computers use special representations for zero
🌟 Quick Reference
Topic
Key Point
Format
M × 2ᴱ where M = mantissa, E = exponent
Normalisation
Positive: 0.1..., Negative: 1.0...
Precision
More mantissa bits = more accuracy
Range
More exponent bits = larger range
Overflow
Number too large to store
Underflow
Number too small to store
11. Key Takeaways
📌 Summary Points
Floating-Point Representation
Format: M × 2ᴱ where M is mantissa, E is exponent
Allows representation of fractional and very large/small numbers
Mantissa contains sign bit and significant digits
Exponent determines binary point position (two's complement)
Conversions
Binary to Denary: Calculate mantissa × 2^(exponent)
Denary to Binary: Convert parts separately, combine, normalise
Fractional parts: Use repeated multiplication by 2
Negative numbers: Work with positive, then apply two's complement
Normalisation
Positive numbers: Must start with 0.1
Negative numbers: Must start with 1.0
Shift bits left, decrease exponent for each shift
Ensures maximum precision and unique representation
Precision vs Range
More mantissa bits → Higher precision, smaller range
More exponent bits → Larger range, lower precision
Always a trade-off between the two
Problems
Rounding errors: Some numbers can only be approximated
Overflow: Number too large to represent
Underflow: Number too small to represent
Zero problem: Cannot represent zero in normalised form