# Binary Addition & Overflow Errors

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 1: Data Representation
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory + Free Practice

---

## Theory & Conceptual Background

Arithmetic addition in binary follows positional place-value rules identical to denary addition, but with a base of 2 where $1 + 1 = 10_2$ (0 with a carry of 1).

Learning Objectives
Add two positive 8-bit binary integers with accuracy.Identify carry bits and explain the causes and consequences of overflow errors in computer registers.

Core Syllabus Theory
1. The Four Fundamental Binary Addition Rules
When adding two binary digits in any column, four possible combinations exist:
$0 + 0 = 0$$0 + 1 = 1$$1 + 1 = 0 \text{ (carry 1 into the next column to the left)}$$1 + 1 + 1 = 1 \text{ (carry 1 into the next column to the left)}$
Always perform binary addition starting from the Least Significant Bit (LSB) on the far right and work column by column towards the Most Significant Bit (MSB) on the far left.
2. Step-by-Step Worked Example (Without Overflow)
Add $01011010_2$ ($90_{10}$) and $00110111_2$ ($55_{10}$):
$$\begin{array}{rcccccccc}
\text{Place Value:} & 128 & 64 & 32 & 16 & 8 & 4 & 2 & 1 \\
\text{Carry Bits:} & 1 & 1 & 1 & 1 & 1 & 1 & & \\
\hline
\text{First Operand:} & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 \quad (90_{10}) \\
\text{Second Operand:} & 0 & 0 & 1 & 1 & 0 & 1 & 1 & 1 \quad (55_{10}) \\
\hline
\text{Result (Sum):} & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 1 \quad (145_{10})
\end{array}$$
Checking in denary: $90 + 55 = 145$. The result $10010001_2 = 128 + 16 + 1 = 145_{10}$. The calculation is completely correct and fits cleanly within the 8-bit register.

3. Overflow Errors in Hardware Registers
An overflow error occurs when the result of a binary arithmetic operation exceeds the maximum representable value for the allocated hardware register size.
In an unsigned 8-bit register, the positional place values allow numbers from $0$ up to $2^8 - 1 = 255_{10}$ ($11111111_2$).
Worked Example: Addition With Overflow
Add $11001000_2$ ($200_{10}$) and $01010000_2$ ($80_{10}$):
$$\begin{array}{rccccccccc}
\text{Carry Out:} & \mathbf{1} & 1 & 0 & 0 & 0 & 0 & 0 & 0 & \\
\hline
\text{Operand 1:} & & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 0 \quad (200_{10}) \\
\text{Operand 2:} & & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \quad (80_{10}) \\
\hline
\text{9-Bit Result:} & \mathbf{1} & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \quad (280_{10})
\end{array}$$
Consequences of Overflow:
Lost Carry Bit: The 8-bit hardware register has no physical flip-flop/latch to store the 9th bit. The carry bit is discarded or pushed into an overflow flag register.Corrupted Result: The accumulator register only holds the lower 8 bits: $00011000_2 = 16 + 8 = 24_{10}$. Instead of the correct sum $280$, the computer computes $24$!Software Impact: Unless software explicitly inspects the CPU overflow flag, this arithmetic corruption can cause unpredictable bugs, incorrect game physics, navigation errors, or system failure.

Exam Tips & Common Pitfalls

  Note: Show Every Carry Bit: In Cambridge IGCSE Paper 1, questions frequently award a dedicated mark for showing your carry bits clearly above each column. Never compute binary addition mentally without writing down carries.
Spotting Overflow: If adding two 8-bit numbers produces a 1 in the carry-out from the 128 column, an overflow error has occurred. State explicitly that the result cannot fit into the 8-bit register.

Key Terminology Glossary
Carry Bit: A bit generated when the sum of two or more bits exceeds the base value (base 2).Most Significant Bit (MSB): The leftmost bit in a binary number, carrying the highest positional place value.Least Significant Bit (LSB): The rightmost bit in a binary number, carrying the lowest positional place value ($1$).Overflow Error: An error that occurs when an arithmetic calculation produces a result too large to be held in the allocated register size.
Written practice and self-review
Two 8-bit unsigned binary integers are added together in a computer CPU: 11001000 (denary 200) and 01010000 (denary 80). Explain why an overflow error occurs during this operation, and describe what happens to the numerical value stored inside the 8-bit accumulator register.
Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: 8-Bit Overflow Error (Multiple choice, 25 XP)

**Instructions:**
Explain what causes an overflow error when two unsigned 8-bit binary integers are added together:

**Options:**
- **A**: The clock speed of the CPU was set too high during execution.
- **B**: The addition produces a 9th carry bit that cannot fit within the allocated 8-bit register.
- **C**: One of the numbers was negative and inverted.
- **D**: The result was divisible by 256.



### Exercise 2: Exam-Style Question: 8-Bit Binary Addition (Binary hex, 35 XP)

**Instructions:**
Add the two 8-bit binary integers: 01011010 (denary 90) and 00110111 (denary 55). Calculate the 8-bit sum and verify whether an overflow occurred:


**Starter Code:**
```text
{"mode":"addition","target_base":2,"bit_width":8,"operands":["01011010","00110111"],"check_overflow":true,"fixed_width":true}
```

**Autotest Expectations:**
- **Calculates the correct 8-bit sum 10010001**: `exact_value` -> Expected: `10010001`
- **Correctly identifies that no overflow occurred**: `overflow_match` -> Expected: `false`

### Exercise 3: Application: Check the reasoning (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Eight-bit 01110101 + 00100110 (write eight result bits): Does 180 + 90 overflow an unsigned eight-bit register: yes or no? Stored result of 180 + 90 as a denary number:


**Starter Code:**
```text
{"prompt":"Application: Check the reasoning","template":"1. Eight-bit 01110101 + 00100110 (write eight result bits): [blank_1]\n2. Does 180 + 90 overflow an unsigned eight-bit register: yes or no? [blank_2]\n3. Stored result of 180 + 90 as a denary number: [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["10011011","yes","14","no","10011101","270","15","255"]}
```


