We can subtract the 5-bit binary numbers 011012 (1310) and 010012 (910) by converting 010012 to its negative equivalent in 2's complement and adding this value to 011012.

  1. First, we need to convert 010012 to its negative equivalent in 2's complement.
    01101   (13)
  - 01001  - (9)
  1. To do this we change all the 1s to 0s and vice versa.
  01001 -> 10110
  1. Then we add 1 to the number to obtain our negative equivalent. Notice that the most-significant digit is now 1 since the number is negative.
  +     1
    10111   (-9)
  1. Next, we add the negative value we computed to 011012. This gives us a result of 1001002. However, since we are only using 5-bit binary numbers, we discard the extra bit on the left side.
    01101   (13)
  + 10111  +(-9)
   100100    (?)
  1. This gives us a final answer of 001002 (or 4).
    01101   (13)
  + 10111  +(-9)
    00100    (4)

Animated version

Let's review the steps for subtracting x from y with an n-bit 2's complement representation.

  1. Negate x using 2's complement.
    1. Reverse all the bits in x.
    2. Add 1 to form -x.
  2. Add -x and y.
  3. Discard any bits greater than n.

Now go back and compare these steps with the steps for 1's complement subtraction. Notice that with 1's complement, you must check for an overflow bit each time you perform a subtraction. If the result has an overflow, you need to add the extra bit to your result to obtain the correct answer. However, with 2's complement, we only need to ignore this extra bit. No other computations are required to find the correct answer. This makes 2's complement a more efficient way of representing signed numbers and performing binary subtraction.