Subtraction Using Two'S Complement Representation

Two's Complement allows us to subtract both positive and negative numbers using the addition operation. Put simply, we:
-convert the decimal number to binary
-convert the number being subtracted into its Two's Complement form in binary
-add the two numbers together
So, we have the following example, which uses a positive result.

Step 1 - Convert the numbers to binary

Decimal Binary
12 00001100
8 (1's Complement) 00001000

Step 2 - Convert the number being subtracted to One's Complement

Decimal Binary
12 00001100
8 (1's Complement) 11110111

Step 3 - Convert the nuumber being subtracted to Two's Complement

Decimal Binary
12 00001100
8 (2's Complement) 11111000

Step 4 - Add the two numbers together

Decimal Binary
12 00001100
8 (2's Complement) 11111000
Result 00000100

Step 5 - Convert the result into decimal form to check the answer

Decimal Binary
4 00000100
12 - 8 = 4

As we can see, the resulting binary number is 4 (and positive, because the leading bit is 0), meaning the equation worked successfully. Now, the following example will produce a negative result:

Step 1 - Convert to binary

Decimal Binary
6 00000110
13 00001101

Step 2 - Convert to the number being subtracted into Two's Complement

Decimal Binary
6 00000110
13 (2's Complement 11110011

Step 3 - Add the two numbers

Decimal Binary
6 00000110
13 (2's Complement 11110011
11111001

We can see that the leading bit of the result (in 2's Complement) is a 1, which indicates that the number is negative. Therefore, there is an additional step.

Step 4 - Reverse the process for the result (Convert back to 1's Complement)

Decimal Binary
6 00000110
13 (2's Complement 11110011
Result (2's Complement) 1111100
Resut (1's Complement) 00000110

Step 5 - Convert the One's Complement by adding one to the result

Decimal Binary
6 00000110
13 (2's Complement 11110011
Result (2's Complement) 1111100
Resut (1's Complement) 00000110
1
Answer in binary 00000111

Step 6 - Convert the answer back to decimal

~ Decimal ~ Binary
7 00000111

Now, we simply add the sign bit, producing the result of -7. Some things to note:
-When we 'carry' over a bit, and it ends up on the left hand side, it is simply ignored. For example:

Decimal 2's Complement
-5 11111011
+12 00001100 +
+7 (1)00000111

-Also, if the two operands have the same signs, the carry bit 1 is carried over, producing an overflow error, as the result is then wrong.
-Binary addition and subtraction uses the fetch-execute cycle, meaning that only two numbers can be added be added at a time. So, if we were to add 5 + 3 + 9, the binary would add 5 and three, store the result, and then add 9 to the result, producing a new result.

Do the Quiz!

Back to Last Page

Home

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License