147k views
1 vote
Why does the 1 1s complement subtraction algorithm work?

User Fiiv
by
7.7k points

1 Answer

4 votes

Final answer:

The 1's complement subtraction algorithm works by adding the 1's complement of the subtrahend to the minuend.

Step-by-step explanation:

The 1's complement subtraction algorithm works by adding the 1's complement of the subtrahend to the minuend. Here are the steps:

  1. Take the 1's complement of the subtrahend by flipping all the bits (changing 1s to 0s and 0s to 1s).
  2. Add the 1's complement of the subtrahend to the minuend using binary addition.
  3. If there is an overflow, add the carry back to the result.
  4. If the original minuend was negative, take the 1's complement of the result to obtain the final answer.

For example, suppose we want to subtract 5 from 9. The 1's complement of 5 is 10, and the 1's complement of 10 is 01. Adding 9 and 01 gives us 10, but since the most significant bit is 1, there is an overflow. Adding the carry back to the result gives us 11, which is the 1's complement of 4, the correct answer.

User Noordeen
by
8.0k points