PyGCSE Python Lab

Binary Arithmetic Trainer

Practice unsigned and signed 8-bit binary addition, subtraction, and logical shifts with step-by-step working. Covers AQA A Level CS (7517) §4.5.4.1–4.5.4.3.

📖 Learn Step-by-Step
00101010
00011011
00101010+00011011=01000101(69 unsigned, 69 signed)

Step-by-step working

0111010 ← carries
00101010 (42 unsigned, 42 signed)
+ 00011011 (27 unsigned, 27 signed)
─────────
01000101 (69 unsigned, 69 signed)

Unsigned vs Signed (8-bit)

Unsigned range:0 to 255
Signed range:−128 to +127

A unsigned:42
A signed:42
B unsigned:27
B signed:27

Key concepts

  • Binary addition follows the same column rules as decimal
  • 1 + 1 = 10 (0, carry 1)
  • 1 + 1 + 1 = 11 (1, carry 1)
  • Overflow occurs when the result exceeds 8 bits

Binary Arithmetic Practice Questions

Use the trainer above to explore binary arithmetic, then try these exam-style questions.

Q1Binary addition

Calculate the sum of these two unsigned 8-bit binary numbers.

0/2 marks

Work from right to left. Enter carries in the bottom row where needed.

1286432168421
Addend 101101001
Addend 210010110
Answer
Carries
Q2Binary addition

Add these two unsigned 8-bit binary numbers. Does overflow occur?

0/2 marks

Work from right to left. Enter carries in the bottom row where needed.

1286432168421
Addend 111010100
Addend 201110010
Answer
Carries
Q3Logical left shift

Perform a logical shift left by 2 places on this 8-bit binary number.

0/1 mark
1286432168421
Original00110100
Left shift by 2
Result
Q4Logical right shift

Perform a logical shift right by 3 places on this 8-bit binary number.

0/1 mark
1286432168421
Original10110000
Right shift by 3
Result
Q5Two's complement

Represent the decimal number −45 as an 8-bit two's complement binary number.

0/2 marks
Denary:-45

Your Answer (8-bit Two's Complement):

1286432168421
Q6Two's complement

Represent the decimal number −100 as an 8-bit two's complement binary number.

0/2 marks
Denary:-100

Your Answer (8-bit Two's Complement):

1286432168421
Quick reference — binary arithmetic

Binary addition rules:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 10 (0 carry 1)
  • 1 + 1 + 1 = 11 (1 carry 1)

Two's complement (for signed numbers):

  • MSB has negative weight (e.g., −128 for 8-bit)
  • To negate: flip all bits, then add 1
  • Subtraction: A − B = A + two's complement of B
  • 8-bit range: −128 to +127

Logical shifts:

  • Shift left: each shift = ×2, vacated bits filled with 0
  • Shift right: each shift = ÷2 (integer), vacated bits filled with 0
  • Bits shifted out are lost permanently
  • Arithmetic shift right preserves the sign bit (not covered here — this is logical shift)

Overflow:

  • Occurs when the result cannot be represented in the available bits
  • Unsigned overflow: carry out of the MSB
  • Signed overflow: result changes sign unexpectedly