Cambridge IGCSE Computer Science (0478) · lesson 3 of 35 · 25 min
Binary Addition Rules
Binary addition follows four simple rules:
- A
- B
- Sum
- Carry
- 0
- 0
- 0
- 0
- 0
- 1
- 1
- 0
- 1
- 0
- 1
- 0
- 1
- 1
- 0
- 1
When adding three bits (A + B + carry-in), the same rules apply but you may get a carry-out of 1 when two or more inputs are 1.
Worked Examples
Add 00110101 + 00011010
00110101
- 00011010
─────────
01001111
53 + 26 = 79 ✓ (01001111 = 64+8+4+2+1 = 79)
Add 11000000 + 01000000 (overflow example)
11000000
- 01000000
─────────
1 00000000 ← 9 bits needed!
192 + 64 = 256, but 8 bits can only hold 0–255. The result overflows — the carry out of bit 7 is lost, leaving 00000000 (incorrect result of 0).
Overflow Explained
Overflow occurs when the result of an arithmetic operation is too large to be stored in the available number of bits. For an 8-bit register, the maximum unsigned value is 255 (11111111). Any result ≥ 256 causes overflow.
Overflow is a real problem in computing — it can cause programs to crash, produce wrong results, or create security vulnerabilities. The processor sets an overflow flag in its status register when overflow occurs, which the operating system or program can check.
8-bit unsigned integers: range 0–255. 16-bit unsigned integers: range 0–65,535. Overflow = carry out of the most significant bit. The CPU sets an overflow flag when overflow is detected. Programmers must check for overflow in safety-critical code.
What is 00001111 + 00000001 in binary?
- 00010000
- 00001111
- 00010001
- 00001110
Answer: 00010000
15 + 1 = 16 = 00010000.
An 8-bit register holds 11111111. Adding 1 causes:
- Result = 256
- Overflow, result wraps to 00000000
- Result = 11111110
- No change
- Answer: 1
The carry out of bit 7 is lost; the register wraps to 00000000.
Which flag does the CPU set when overflow occurs?
- Zero flag
- Carry flag
- Overflow flag
- Sign flag
Answer: Overflow flag
The overflow flag in the status register is set.
Previous lesson: Converting between binary, denary, and hexadecimal
Back to Cambridge IGCSE Computer Science (0478)
Next lesson: Two’s complement representation