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
02 ยท Core Concept
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.
โก 03 ยท Interactive Tool
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.
๐จ
โ
04 ยท Worked Example โ Overflow
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?
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 โ]
05 ยท Exam Questions โ Overflow
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
06 ยท Core Concept
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):
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.
โก 07 ยท Interactive Tool
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.
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 โ]
09 ยท Exam Questions โ Shifting
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]
โ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]
10 ยท Combined Quiz
6-Question Challenge โ Overflow & Shifting
3 overflow questions + 3 shifting questions. Answer all 6 for your XP badge.