Adding binary numbers, detecting overflow, shifting left and right, and representing negative numbers using two's complement.
Add two 8-bit binary numbers and identify overflow
Apply left and right binary shifts and explain the effect
Represent negative numbers using two's complement
Add a positive and negative binary number using two's complement
Binary addition
Adding binary numbers follows the same principle as adding denary numbers: you add column by column from right to left, carrying over when the result exceeds the maximum digit.
In denary, when you add 7+5=12, you write 2 and carry 1. In binary, the only possible values per column are 0 and 1, so the rules are simpler:
An 8-bit number can store values from 0 to 255. If the result of an addition exceeds 255, the 9th bit cannot be stored -- this is called overflow.
Overflow occurs when: the carry out of the most significant bit (the leftmost column) produces a 1 that cannot fit in the 8-bit result. The stored result is wrong -- it wraps around to a small number instead of the correct large one. In an exam, state that the result is incorrect/truncated because it exceeds what 8 bits can store.
Carry: 1 1 1 0 0 0 0 0
A: 1 1 0 0 1 0 1 0 (= 202)
B: + 0 1 1 1 0 1 1 0 (= 118)
---------------
Result: 0 0 1 0 0 0 0 0(= 32 -- WRONG! Overflow!)
Correct answer: 202 + 118 = 320, which cannot fit in 8 bits.
The carry out of the leftmost column (shown in red) indicates overflow.
Binary shifts
Shifting all bits left or right is the fastest way a computer can multiply or divide by powers of 2.
Left shift by 1 place: multiplies the value by 2. Every bit moves one column to the left. A 0 fills the rightmost position. Any bit shifted beyond the leftmost column is lost.
Right shift by 1 place: divides the value by 2 (integer division). Every bit moves one column to the right. A 0 fills the leftmost position. The rightmost bit is lost.
Exam question type: "Describe the binary shift that can be used to multiply any number by 8." Answer: a left shift of 3 places (since 23=8). You must state both the direction AND the number of places.
Representing negative numbers: two's complement
Standard binary can only represent positive numbers. To store negative numbers, computers use two's complement. The most significant bit (leftmost) becomes a sign bit: 0 means positive, 1 means negative.
In two's complement, the leftmost bit has a negative weight. For an 8-bit two's complement number:
The elegance of two's complement is that you can add positive and negative numbers using standard binary addition -- no special rules needed for the hardware.
2. The result of adding two 8-bit numbers is 100110010, which has 9 bits. What has occurred?
The numbers were subtracted instead of added
Overflow -- the result exceeds 255 and cannot be stored in 8 bits
The result is stored correctly using a 9th bit
A binary shift occurred automatically
Overflow occurs when the result exceeds what 8 bits can hold (0-255). The 9th bit cannot be stored and the result is incorrect.
3. What is the result of a 2-place right binary shift on 01110111?
00011101
11011100
00111011
11101110
01110111 (=119) shifted right 2 places: the two rightmost bits (11) are lost, zeros fill from the left. Result: 00011101 (=29). Note: 119÷4=29 remainder 3.
4. Describe the binary shift needed to multiply a number by 8.
Right shift by 3 places
Left shift by 8 places
Left shift by 3 places (since 23=8)
Right shift by 8 places
Multiplying by 8 requires a left shift of 3 places (23=8). Left shift = multiply, right shift = divide. The number of places = the power of 2.
5. Using two's complement, what is the 8-bit representation of -19?
Two's complement allows a computer to subtract by adding. How? If you want to calculate A - B, you can instead calculate A + (-B). Why does this make hardware simpler?
The processor only needs an adder circuit, not a separate subtraction circuit. To compute A - B, the processor converts B to its two's complement (negation is a simple bit flip plus increment) and then adds it to A. This means a single hardware block handles both addition and subtraction, reducing transistor count and complexity. All modern CPUs use this approach.
Overflow is a real security concern. In 2018, a vulnerability allowed attackers to trick a program into allocating a very small block of memory by causing an integer overflow. Why would this be dangerous?
If a program calculates the size of a memory allocation using arithmetic that overflows, the resulting value wraps around to a small number. The program allocates a tiny buffer but believes it has allocated a large one. When data is then written, it overflows the small buffer and writes into adjacent memory -- a "buffer overflow" attack. This can allow attackers to overwrite return addresses or function pointers, gaining control of program execution. Overflow bugs are behind many historical security vulnerabilities.
32-40 min: Workbench tool practice (all three tabs)
Common Misconceptions
Forgetting the carry row entirely, or writing carries below the numbers instead of above.
"A right shift fills zeros from the RIGHT" -- zeros fill from the LEFT (the most significant end).
"Two's complement negative numbers have the same range as positives" -- range is -128 to +127 for 8-bit, not -127 to +127. There is one extra negative because zero is treated as positive.
"Overflow means the computer crashes" -- overflow means the result is silently incorrect. Programs must check for it explicitly.
Applying the flip on only some bits during two's complement. ALL 8 bits must be flipped, then +1.
Marking Guidance
Binary addition (2 marks): 1 mark for the carry row shown correctly, 1 mark for the correct result. If only the result is shown with no working, 1 mark maximum.
Overflow (2 marks): 1 mark for stating overflow has occurred, 1 mark for explaining the result cannot fit in 8 bits (or "carry out of the MSB"). Saying "the answer is wrong" alone earns 0 for the explanation mark.
Binary shift (2 marks): 1 mark for direction, 1 mark for number of places. Both are required.
Two's complement: Method marks available. Students who flip correctly but make an addition error in +1 can still earn the method mark if working is shown.
Error Analysis Activity
Show this and ask: "A student adds 10110011 + 01110101 and gets 00101000. Is this correct? If not, what went wrong?" (Expected: 202+117=319, overflow. The student's answer is the lower 8 bits of 100101000.)
The student correctly added but did not identify the overflow. The 9th bit carry was lost. Students must check whether the result is larger than 255 before accepting it.
Differentiation
Grade 4 Binary addition of two numbers without overflow. Identify that overflow occurs. Left shift by 1 place.
Grade 7 Addition with carries, identify overflow, describe its effect. Shifts by multiple places. Two's complement for simple numbers.
Grade 9 Verify two's complement results using the -128 place value. Explain why two's complement allows hardware to subtract by adding. Discuss real-world consequences of overflow.
Exit Tickets
Add 10110010 + 01011100. Show carry row. State whether overflow occurs. [3 marks]
Describe the binary shift to multiply by 4. What is the result if applied to 00001010? [2 marks]
Convert -37 to 8-bit two's complement. Show your working. [2 marks]