Binary addition and shifts

GCSE Computer Science revision notes, key terms and practice questions.

Binary addition

  • The rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1), and 1 + 1 + 1 = 11 (write 1, carry 1).
  • Work from right to left, carrying just as in denary. 0101 1010 + 0011 0111 = 1001 0001, which is 90 + 55 = 145.

Overflow

  • Overflow happens when a result is too big to fit in the number of bits available. In 8 bits, 200 + 100 = 300 needs 9 bits, so the extra bit is lost and the stored answer is wrong.

Binary shifts

  • A logical shift left by n places multiplies the number by 2ⁿ. 0000 0110 (6) shifted left 2 places is 0001 1000 (24).
  • A logical shift right by n places divides the number by 2ⁿ. 0001 1000 (24) shifted right 3 places is 0000 0011 (3).
  • The gaps are filled with 0s, and bits shifted off the end are lost. So 0000 0111 (7) shifted right 1 place is 0000 0011 (3), not 3.5.

Negative numbers (Edexcel)

  • Two's complement stores negative numbers. In 8 bits, the leftmost bit is worth −128 instead of 128.
  • 1111 1110 = −128 + 64 + 32 + 16 + 8 + 4 + 2 = −2.

Key terms

Carry
A 1 moved to the next column when a column adds up to 2 or 3.
Overflow
When a result needs more bits than are available.
Logical shift
Moving all the bits left or right, filling the gaps with 0s.
Shift left
Moves the bits left: each place multiplies the number by 2.
Shift right
Moves the bits right: each place divides the number by 2.
Two's complement
A way of storing negative numbers in binary, where the leftmost bit has a negative value.

Practise Binary addition and shifts: 12 questions