- Home
- Lessons
- GCSE & IGCSE Computer Science
- Binary addition, overflow and shifts
Binary addition, overflow and shifts
🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.
Computers add binary numbers column by column, just like you add in denary. Shifting bits left or right is a quick way to multiply or divide by 2.
Binary addition rules
0 + 0 = 0
0 + 1 = 1
1 + 1 = 0 carry 1
1 + 1 + 1 = 1 carry 1
Work from the right-hand column, carrying into the next column.
0 + 1 = 1
1 + 1 = 0 carry 1
1 + 1 + 1 = 1 carry 1
Work from the right-hand column, carrying into the next column.
Overflow
8 bits can only hold up to 255 (unsigned).
If a result needs a 9th bit, there is no room for it. This is overflow and the stored result is wrong.
11001000 (200) + 01000000 (64) = 264, which needs 9 bits.
If a result needs a 9th bit, there is no room for it. This is overflow and the stored result is wrong.
11001000 (200) + 01000000 (64) = 264, which needs 9 bits.
Binary shifts
Logical shift left: move every bit left, fill the gaps on the right with 0. Each place multiplies by 2.
Logical shift right: move every bit right, fill on the left with 0. Each place divides by 2 (losing any remainder).
Arithmetic shift right: used for signed numbers. The left gaps are filled with copies of the sign bit, so negative numbers stay negative.
00010110 (22) shifted left 2 places = 01011000 (88)
Logical shift right: move every bit right, fill on the left with 0. Each place divides by 2 (losing any remainder).
Arithmetic shift right: used for signed numbers. The left gaps are filled with copies of the sign bit, so negative numbers stay negative.
00010110 (22) shifted left 2 places = 01011000 (88)
Add 00110101 and 00011010.
- 53 + 26 in denary
- Add column by column from the right, carrying 1s.
Answer: 01001111 (79)
1 + 1 = 0 carry 1. A result too big for the bits available causes overflow. Logical shifts fill with 0s: left multiplies by 2 per place, right divides by 2. Arithmetic right shifts copy the sign bit.
The interactive lesson includes the diagrams for this topic.
Check you have got it
Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.