📑 Contents

Chapter 13.3: Floating-Point Numbers, Representation and Manipulation

9618 Computer Science - AS Level

📚 Learning Objectives
📋 Prior Knowledge Required
💡 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
Floating-Point Number Structure MANTISSA (8 bits) Sign bit + Fraction part EXPONENT (8 bits) Power of 2 (Two's complement) Binary point assumed here Number = Mantissa × 2^(Exponent)
💡 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
  1. Add up the mantissa values where a 1 bit appears
  2. Add up the exponent values where a 1 bit appears
  3. Use the formula: Result = Mantissa × 2^(Exponent)

Example: Convert this binary floating-point number to denary:

Bit Position -1 ½ ¼ 1/16 1/32 1/64 1/128
Mantissa 10110100

Exponent: 00000100 (= 4 in denary)

Solution:
M = -1 + ¼ + ⅛ + 1/32 = -32/32 + 8/32 + 4/32 + 1/32 = -19/32
E = 4
Result = -19/32 × 2⁴ = -19/32 × 16 = -9.5

2.2 Method 2: Move the Binary Point

📝 Alternative Method
  1. Write the mantissa as 0.xxxxxx (or 1.xxxxxx for negative)
  2. If exponent is positive, move binary point RIGHT by that many places
  3. If exponent is negative, move binary point LEFT by that many places
  4. Convert the resulting binary to denary
Same Example:
Mantissa = 0.1011010 (reading the bits after sign manipulation for negative)
Exponent = 4, so move binary point 4 places RIGHT
Result: 1011.010 = 8 + 2 + 1 + ¼ = 11.25
(Note: For negative numbers, apply two's complement first)
Moving the Binary Point Before: 0.1011010 × 2⁴ Move point 4 places right After: 1011.010 = 11.25₁₀

3. Converting Denary to Binary Floating-Point

3.1 Converting Positive Numbers

📝 Method for Positive Numbers
  1. Convert the integer part to binary
  2. Convert the fractional part using repeated multiplication by 2
  3. Combine to get binary representation
  4. Move binary point until 0.1xxxxx format (normalise)
  5. The number of moves becomes the exponent

Example: Convert +4.5 to binary floating-point (8-bit mantissa, 8-bit exponent)

Step 1: 4 = 0100 in binary
Step 2: 0.5 × 2 = 1.0 → 0.1 in binary
Step 3: Combined: 0100.1
Step 4: Normalise: 0.1001 (moved point 3 places left)
Step 5: Exponent = 3 = 00000011
Result: Mantissa = 01001000, Exponent = 00000011

3.2 Converting Fractional Parts

To convert fractional parts, use repeated multiplication by 2:

Calculation Whole Part Binary Digit
0.40625 × 2 = 0.8125 0 0
0.8125 × 2 = 1.625 1 1
0.625 × 2 = 1.25 1 1
0.25 × 2 = 0.5 0 0
0.5 × 2 = 1.0 1 1

0.40625₁₀ = 0.01101₂

3.3 Converting Negative Numbers

⚠️ Important: Negative Numbers

For negative numbers, first convert the positive version, then apply two's complement to get the mantissa. The sign bit will be 1.

Example: Convert -10.375 to binary floating-point

Step 1: +10.375 = 01010.011
Step 2: Normalise: 0.1010011 × 2⁴
Step 3: Apply two's complement to mantissa bits (excluding sign bit)
Step 4: Add sign bit = 1
Result: Mantissa = 10101101, Exponent = 00000100
🧠 Memory Trick

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
Why Normalise? Same value, different representations: 0.1000000 × 2¹ = 2 0.0100000 × 2² = 2 0.0010000 × 2³ = 2 Only the first is normalised! ✓ Maximum precision ✓ Unique representation ✓ Easier arithmetic

4.1 How to Normalise

📝 Normalisation Steps

For positive numbers (starting with 0.xxx):

  1. Shift the bits LEFT until mantissa begins with 0.1
  2. For each shift left, DECREASE the exponent by 1

For negative numbers (starting with 1.xxx):

  1. Shift the bits LEFT until mantissa begins with 1.0
  2. 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!

Verification: 7/8 × 2³ = 7/8 × 8 = 7 ✓ Correct value maintained
💡 Exam Tip

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 vs Range Trade-off (16-bit total) Case 1: High Precision 12-bit mantissa 4-bit exponent Max: 2047/2048 × 2⁷ Case 2: Balanced 8-bit mantissa 8-bit exponent Max: 127/128 × 2¹²⁷ Case 3: High Range 4-bit mantissa 12-bit exponent Max: 7/8 × 2²⁰⁴⁷ High accuracy Small range Moderate both Good balance Poor accuracy Huge range More Precision More Range
⚠️ Important: The Trade-off
💡 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.

Example: Converting 5.88 to binary floating-point

0.88 × 2 = 1.76 → 1
0.76 × 2 = 1.52 → 1
0.52 × 2 = 1.04 → 1
0.04 × 2 = 0.08 → 0
... and it continues infinitely!

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.

6.3 Underflow

⚠️ Underflow Error

Underflow occurs when a calculation produces a number smaller than the minimum that can be represented.

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:

Computers use special representations to handle zero.

Floating-Point Number Range OVERFLOW Too large UNDERFLOW Too small VALID RANGE Largest negative Zero (special case) Largest positive

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):

Mantissa: 01011010 | Exponent: 00000100

Solution:

Step 1: Identify mantissa values (binary point after sign bit):
Sign = 0 (positive), Fraction = 1011010
Values: ½ + ⅛ + ¼ + 1/32 = 16/32 + 4/32 + 8/32 + 1/32 = 29/32

Step 2: Identify exponent: 00000100 = 4

Step 3: Calculate: 29/32 × 2⁴ = 29/32 × 16 = 29/2 = 14.5

Example 2: Convert Denary to Binary Floating-Point

📝 Question

Convert +0.171875 to binary floating-point (8-bit mantissa, 8-bit exponent)

Solution:

Step 1: Convert fractional part:
0.171875 = 11/64 = 8/64 + 2/64 + 1/64 = ⅛ + 1/32 + 1/64
In binary: 0.001011

Step 2: Normalise: 0.001011 → 0.1011 (move point 2 places right)
Exponent = -2

Step 3: Two's complement of -2: 11111110

Result: Mantissa = 01011000, Exponent = 11111110

Example 3: Normalise a Number

📝 Question

Normalise this binary floating-point number: 1.1101100 00001010

Solution:

Step 1: This is negative (starts with 1), so we need to get 1.0xxxxx format

Step 2: Shift bits LEFT until first two bits are different:
1.1101100 → 1.1011000 (1 shift) → 1.0110000 (2 shifts)

Step 3: Exponent was 10, reduce by 2 → 8 (00001000)

Result: Mantissa = 10110000, Exponent = 00001000 ✓ Normalised!
💡 Verification Tip

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]

Answer:

  • Sign bit = 1 (negative number)
  • Fraction part: 1010100
  • Mantissa value: -1 + ¼ + 1/16 + 1/64 = -64/64 + 16/64 + 4/64 + 1/64 = -43/64
  • Exponent = 3
  • Result: -43/64 × 2³ = -43/64 × 8 = -43/8 = -5.375
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.

Original: 0.0011100 = 1/8 + 1/16 + 1/32 = 7/32. Times 2⁵ = 7/32 × 32 = 7. Normalised: 7/8 × 2³ = 7. ✓ Correct!

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)
  • Exponent = 3 = 0011 (4 bits)

Final Answer: Mantissa = 1010, Exponent = 0011

Verification: Mantissa = -1 + ¼ = -3/4. Result = -3/4 × 2³ = -3/4 × 8 = -6 ✓ Correct!

9. Glossary

Mantissa

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
💡 Converting Binary Floating-Point to Denary
💡 Converting Denary to Binary Floating-Point
🧠 Memory Trick: Exponent Direction
💡 When Normalising
❌ Common Mistakes to Avoid

10. Exam Success Tips (Part 2)

💡 Precision vs Range Questions
🧠 Memory Trick: Mantissa vs Exponent
💡 Understanding Rounding Errors
⚠️ Key Points for Exam Questions
  1. Always show your working - marks are awarded for method
  2. State assumptions clearly (e.g., "assuming 8-bit mantissa...")
  3. Check your answer makes sense (is the sign correct? Is the magnitude reasonable?)
  4. For conversion questions, verify by converting back
  5. Use correct terminology: mantissa, exponent, normalise, two's complement
💡 The Zero Problem

Remember: Zero cannot be represented in normalised floating-point because:

🌟 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

Conversions

Normalisation

Precision vs Range

Problems

Chapter 13.3 Summary Diagram Floating-Point Mantissa Exponent Normalisation Errors Precision Range 0.1 or 1.0 Overflow/Underflow