๐Ÿ”ข Chapter 1 ยท Topics 4 & 5 ยท Paper 1 & 2

Binary Overflow
& Binary Shifting

When numbers break their boundaries โ€” and how to multiply without multiplying

๐Ÿ”ฅ 01 ยท Did You Know?

On June 4th 1996, the Ariane 5 rocket exploded 37 seconds after launch, destroying a โ‚ฌ370 million spacecraft. The cause? A 64-bit floating point number was converted into a 16-bit integer โ€” the value was too large to fit, overflow occurred, and the navigation system crashed. The entire mission was lost to a bug that took engineers minutes to find but cost a decade of development. Meanwhile, binary shifting is used by every image processor, audio encoder, and graphics engine on the planet โ€” shifting bits left multiplies values, shifting right divides them, without a single multiplication instruction. Faster. Cheaper. Elegant. These two topics sit on either side of the same truth: bit boundaries are a hard physical limit, and every professional programmer must know what happens at the edge.

๐Ÿšจ Section 1 โ€” Binary Overflow

What is Binary Overflow?

Overflow occurs in binary addition when the result is too large to be stored in the number of bits available. In an 8-bit system, the maximum value is 255. Any result above 255 cannot be correctly stored โ€” a carry bit is generated out of the Most Significant Bit (MSB) column, and that bit is lost. The stored result becomes incorrect.

โš ๏ธ Overflow condition: a carry is generated out of the leftmost (MSB) column. This carry bit cannot be stored โ€” it is discarded. The 8-bit result is wrong.
โœ“ No Overflow โ€” 60 + 50 = 110
carry:  0 0 1 1 1 0 0 0
A=60:  0 0 1 1 1 1 0 0
B=50:  0 0 1 1 0 0 1 0
 =110: 0 1 1 0 1 1 1 0
No carry out of MSB. Result 01101110 = 110 โœ“ Stored correctly.
โœ— Overflow โ€” 200 + 100 = 300
carry:  1 1 1 0 0 1 0 0
A=200: 1 1 0 0 1 0 0 0
B=100: 0 1 1 0 0 1 0 0
cโ†’100101100
Carry OUT of MSB. Stored result 00101100 = 44 โœ— WRONG. True answer 300 > 255.

How to Check for Overflow

1

Perform the addition normally. Write the carry row clearly above the numbers.

2

Check the carry out of the leftmost (128s / MSB) column. If there is a carry out โ†’ overflow has occurred.

3

Quick denary check: add the two denary values. If the sum exceeds 255 โ†’ overflow will always occur in 8 bits.

4

State the overflow explicitly in your answer. Write: "Overflow has occurred โ€” the result exceeds 255 and cannot be stored correctly in 8 bits."

โš ๏ธ Common Exam Mistakes

โŒ

Confusing overflow with a wrong answer โ€” overflow is a specific condition: carry out of the MSB. A wrong carry in the middle of the sum is just an arithmetic error, not overflow.

โŒ

Not stating overflow explicitly โ€” even if your addition is correct, you must write "overflow has occurred" to earn the dedicated mark.

โŒ

Writing the 9-bit result โ€” in an 8-bit system, the overflow carry bit is lost. The stored answer is only the 8 rightmost bits, even though they are wrong.

๐Ÿ†
Cambridge Exam Tip: Overflow questions are typically 1 mark for detecting it and 1 mark for explaining it. Both marks require you to (1) identify the carry out of the MSB, and (2) state that the result cannot be stored correctly in the given number of bits.
Overflow Detector
// Enter two 8-bit numbers ยท See the full addition ยท Overflow detected live
Load an example:
200+70
โœ“ ok
176+97
overflow
255+1
overflow
127+1
โœ“ ok
128+128
overflow
100+50
โœ“ ok
A = 0
B = 0
โš  Enter exactly 8 bits (0s and 1s only) in both fields.
๐Ÿšจ
โœ…

Does 10110011 + 01110101 Overflow?

Work through each step before revealing โ€” this is a classic 4-mark exam question.

๐Ÿ“‹ Question: Add the binary numbers 10110011 and 01110101. State whether overflow occurs, giving a reason. [4]
1
๐Ÿ”ข Identify the values
Convert both numbers to denary for a quick overflow check. What are the values?
โ–ถ Click to reveal
10110011 = 128+32+16+2+1 = 179 01110101 = 64+32+16+4+1 = 117 Denary sum: 179 + 117 = 296 296 > 255 โ†’ overflow will occur โš 
2
โž• Perform the addition with carries
Add column by column right to left. Show the full carry row.
โ–ถ Click to reveal
carry: 1 1 1 0 1 0 1 0 A: 1 0 1 1 0 0 1 1 B: 0 1 1 1 0 1 0 1 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ R: 0 0 1 0 1 0 0 0 carry OUT of MSB col = 1 โ†’ OVERFLOW โœ—
3
โœ… State the conclusion
What is the stored result, and what must you state about overflow?
โ–ถ Click to reveal
The 8-bit result stored = 00101000 = 40 This is INCORRECT โ€” the true answer is 296. Overflow HAS occurred: โ€” A carry was generated out of the MSB (128s) column โ€” 296 > 255, so the result cannot be stored in 8 bits โ€” The carry-out bit is lost; the stored value (40) is wrong [4 marks: carry row โœ“ | result bits โœ“ | overflow stated โœ“ | reason โœ“]

Cambridge-Style Practice

Show the carry row in every addition question.

Question 1
3 marks
Add the 8-bit binary numbers below. State whether overflow occurs and justify your answer.
A: 11010000 (208) B: 01010000 (80)
โœ“Carry row: 11000000[1]
โœ“8-bit result: 00100000 (carry out of MSB is lost)[1]
โœ“Overflow has occurred โ€” 208+80=288 > 255. Carry generated out of MSB column. Result (32) is incorrect.[1]
Question 2
2 marks
Explain what is meant by overflow in the context of binary addition, and state the condition that causes it.
โœ“Overflow occurs when the result of binary addition is too large to be stored in the available number of bits / exceeds the maximum value (255 for 8 bits)[1]
โœ“It is caused when a carry is generated out of the most significant bit (MSB) column โ€” this carry bit is lost and the stored result is incorrect[1]
Question 3
1 mark
A programmer adds two 8-bit values: 130 and 130. Without performing the full binary addition, explain how you can tell overflow will occur.
โœ“130 + 130 = 260, which exceeds 255 โ€” the maximum value storable in 8 bits. Therefore overflow will occur.[1]
โฌ…โžก Section 2 โ€” Binary Shifting

What is Binary Shifting?

Binary shifting moves all bits in a number a set number of positions left or right. It is the most efficient way a CPU can multiply or divide by powers of 2 โ€” much faster than performing actual multiplication. Vacated positions are filled with 0s. Bits that fall off the end are lost.

โšก Key rule: Left shift ร— 2 per place. Right shift รท 2 per place. Shift left by 3 = multiply by 2ยณ = ร—8.
โฌ…
Left Shift (SHL)
ร— 2 per place shifted
Bits move left. 0s fill from the right. The leftmost bit(s) are lost. If a 1 bit is lost โ€” overflow occurs and the result is incorrect.
โžก
Right Shift (SHR)
รท 2 per place shifted
Bits move right. 0s fill from the left. The rightmost bit(s) are lost (remainders discarded โ€” integer division).

Left Shift by 2 โ€” 00010110 (22) โ†’ 01011000 (88)

Before shift:
original
0
0
0
1
0
1
1
0
= 22
โฌ‡ shift left 2
After shift (zeros fill right, leftmost 2 bits lost):
result
0
1
0
1
1
0
0
0
= 88 โœ“ (22 ร— 4)
Lost bits: 0, 0 (both were 0 โ€” no overflow). Filled: two 0s from right.

Right Shift by 3 โ€” 10110000 (176) โ†’ 00010110 (22)

Before shift:
original
1
0
1
1
0
0
0
0
= 176
โฌ‡ shift right 3
After shift (zeros fill left, rightmost 3 bits lost):
result
0
0
0
1
0
1
1
0
0
0
0
โ† 3 bits lost (discarded)
Result: 00010110 = 22. Check: 176 รท 8 = 22 โœ“ (integer division, remainder discarded)

โš ๏ธ Common Exam Mistakes

โŒ

Filling with 1s instead of 0s โ€” vacated positions are always filled with 0s in a logical shift. Never 1s.

โŒ

Confusing the direction of multiplication โ€” left shift = bigger number (ร—2). Right shift = smaller number (รท2). Students sometimes reverse this.

โŒ

Not accounting for lost bits โ€” if a 1 bit is shifted off the left edge during a left shift, the result will be wrong (overflow). Always check what was lost.

๐Ÿ†
Cambridge Exam Tip: Shift questions almost always ask you to show the result AND state the equivalent denary operation (e.g. "this is equivalent to multiplying by 4"). Write both. If the question says "logical shift" it always means fill with 0s โ€” no sign extension.
Shift Visualiser
// Enter a binary number ยท Choose direction & places ยท Watch bits slide
Quick examples:
00001010
Left 2
00110000
Right 1
10110100
Right 2
00000111
Left 3
11111111
Right 1
01001001
Left 2
Direction:
Places:
โš  Please enter exactly 8 bits using only 0s and 1s.

Shift 00001110 Left by 3 Places

A classic exam-style question combining the shift operation with the multiplication equivalence.

๐Ÿ“‹ Question: The binary number 00001110 is logically shifted left by 3 places. (a) Write the result. (b) State the denary value before and after. (c) State the multiplication this represents. [3]
1
๐Ÿ“Š Identify original value
Convert 00001110 to denary. Which bits are set to 1?
โ–ถ Click to reveal
00001110 โ†’ bits at 8, 4, 2 are 1 = 8 + 4 + 2 = 14 Original denary value = 14
2
โฌ… Perform the left shift ร—3
Move all bits 3 positions to the left. What fills the right? What is lost from the left?
โ–ถ Click to reveal
Before: 0 0 0 0 1 1 1 0 โฌ… shift left 3 โฌ… After: 0 1 1 1 0 0 0 0 3 zeros fill from the RIGHT. 3 leftmost bits (0, 0, 0) are LOST โ€” all zeros, so no overflow. Result: 01110000
3
โœ… Verify and state the operation
What is the denary value after the shift? Does the ร— rule hold?
โ–ถ Click to reveal
01110000 = 64 + 32 + 16 = 112 Before: 14 After: 112 14 ร— 2ยณ = 14 ร— 8 = 112 โœ“ Left shift by 3 = multiply by 2ยณ = ร—8 No overflow (no 1-bits were lost from the left edge). [3 marks: result โœ“ | denary before/after โœ“ | ร—8 stated โœ“]

Cambridge-Style Practice

Show the full bit layout โ€” before and after โ€” in your answer.

Question 4
3 marks
The 8-bit binary number 00011001 is logically shifted right by 2 places. Write the resulting binary number, state the denary values before and after, and state what arithmetic operation this represents.
โœ“Result: 00000110 (bits shifted 2 right, 00 fill from left, 01 lost from right)[1]
โœ“Denary before: 25 (16+8+1). Denary after: 6 (4+2)[1]
โœ“Equivalent to dividing by 4 (2ยฒ) โ€” integer division, remainder discarded (25 รท 4 = 6 remainder 1)[1]
Question 5
2 marks
A programmer shifts the binary number 10000001 left by 1 place. Explain why the result is not simply double the original value.
โœ“Result of shift: 00000010. The MSB (the 1-bit in the 128 column) is shifted off and lost.[1]
โœ“The original value is 129 (128+1). Doubling would give 258, which exceeds 255. A 1-bit was lost from the left (overflow), so the result (2) is incorrect โ€” this left shift causes overflow.[1]
Question 6
2 marks
State what happens to bits when a binary number is logically shifted left. Include what fills the vacated positions and what happens to bits that move beyond the boundary.
โœ“Vacated positions on the right are filled with 0s (zeros)[1]
โœ“Bits that move beyond the left boundary (MSB) are lost / discarded. If any lost bit is a 1, overflow has occurred and the result is incorrect.[1]

6-Question Challenge โ€” Overflow & Shifting

3 overflow questions + 3 shifting questions. Answer all 6 for your XP badge.

Score:
0 / 6
๐Ÿ…
Topics 4 & 5 Complete โ€” Overflow & Shift Expert!
+100 XP ยท Chapter 1 ยท Data Representation