Perform binary addition and subtraction

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – 1.1 Data Representation

1.1 Data Representation

Objective: Perform binary addition and subtraction

This note explains how to add and subtract binary numbers, a fundamental skill for understanding how computers manipulate data.

1. Binary Addition

Binary addition follows the same principle as decimal addition but uses only two digits: 0 and 1. The basic rules are shown in the truth table below.

ABSumCarry
0000
0110
1010
1101

When adding multi‑bit numbers, start at the right‑most (least significant) bit and move left, carrying any overflow to the next column.

Example: \$10112 + 01102\$

  1. Write the numbers one under the other, aligning the bits.
  2. Add each column using the table above, remembering the carry.

1 0 1 1

+ 0 1 1 0

----------

Carry: 1 1 0 0

Result:1 0 0 0 1

Result: \$10112 + 01102 = 100012\$ (which is \$11{10} + 6{10} = 17{10}\$).

2. Binary Subtraction

Binary subtraction can be performed directly using borrowing, or more efficiently using the two’s complement method.

2.1 Direct Borrow Method

The rules are analogous to decimal subtraction:

  • If the minuend bit is greater than or equal to the subtrahend bit, subtract normally.
  • If the minuend bit is 0 and the subtrahend bit is 1, borrow 1 from the next higher bit (equivalent to borrowing 2 in decimal).

Example: \$101012 - 001112\$

1 0 1 0 1

- 0 0 1 1 1

-------------

0 1 1 1 0

Result: \$101012 - 001112 = 011102\$ (which is \$21{10} - 7{10} = 14{10}\$).

2.2 Two’s Complement Method

Two’s complement provides a uniform way to perform subtraction by converting the subtrahend to its negative representation and then adding.

  1. Determine the number of bits required (including a sign bit).
  2. Find the binary representation of the subtrahend.
  3. Invert all bits (one’s complement).
  4. Add 1 to obtain the two’s complement.
  5. Add this result to the minuend.
  6. If a carry out of the most‑significant bit occurs, discard it.

Example: \$101012 - 001112\$ using 5‑bit two’s complement

  1. Subtrahend: \$00111_2\$
  2. One’s complement: \$11000_2\$
  3. Two’s complement: \$11001_2\$ (add 1)
  4. Add to minuend:

    1 0 1 0 1

    + 1 1 0 0 1

    -------------

    1 0 0 1 0 0

  5. Discard the overflow carry (the leftmost 1): result \$00100_2\$.

Result: \$001002 = 4{10}\$, which is the correct difference \$21{10} - 7{10} = 14_{10}\$ when interpreted as a signed 5‑bit number (the example demonstrates the importance of choosing enough bits to avoid overflow).

3. Practice Questions

  1. Add \$11012\$ and \$01112\$. Show each step.
  2. Subtract \$01012\$ from \$10102\$ using the direct borrow method.
  3. Subtract \$00102\$ from \$01102\$ using two’s complement with a 4‑bit word length.
  4. Explain why two’s complement allows a single addition circuit to handle both addition and subtraction.

4. Summary

  • Binary addition uses a simple carry rule; the result may be one bit longer than the operands.
  • Binary subtraction can be performed by borrowing or by adding the two’s complement of the subtrahend.
  • Two’s complement simplifies hardware design because subtraction becomes addition, and it uniquely represents negative numbers.

Suggested diagram: A step‑by‑step illustration of binary addition with carries, and a separate diagram showing the two’s complement conversion process.