PyGCSE Python Lab

Binary Arithmetic — Addition, Subtraction & Shifts

Learn how to perform binary addition, subtraction using two's complement, and logical/arithmetic shifts with step-by-step worked examples.

📚 Learning Steps

💡 Study Tips
  • • Read through at your own pace
  • • Try the interactive simulators hands-on
  • • Study the pseudocode — it appears in exams
  • • Quiz yourself before moving on

Step 1: Unsigned Binary Addition

📖 Theory

Binary addition follows the same rules as decimal, but with only two digits (0 and 1).

Addition rules:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 (write 0, carry 1)
1 + 1 + 1 = 11 (write 1, carry 1)

Worked example: 01101001 + 00110101

  01101001   (105)
+ 00110101   ( 53)
----------
  10011110   (158)

Work from right to left, just like decimal addition. When the sum is 2 (binary 10), write 0 and carry 1. When the sum is 3 (binary 11), write 1 and carry 1.

🎯 Key Points
  • Work right to left, carrying 1 when the column sums to 2 or 3
  • 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (carry), 1 + 1 + 1 = 11 (carry)
  • Unsigned overflow occurs when there is a carry out of the MSB
  • 8-bit unsigned range: 0 to 255
0/5 steps completed