3
votes

I generally understand the concept of 2's complement. When converting a value to 2's complement for subtraction, simply negate each digit of the number to get 1's complement and add 1. When calculating the result of something like 2-2 in binary, you first convert -2 to 2's complement, (I like to use 4 bit representations) 0010 is turned into 1101 and then into 1110. Then you evaluate 0010 + 1110 and get 0000 and the overflowed 1 is truncated.

However, what about a problem like 2-3? So I did the same operation. 2 is 0010 and the 2's complement of 3 (0011) is 1101. So 0010 + 1101 results in 1111 and no overflow. The result is 15. 15 is not negative 1. Am I missing a crucial point about how 2's complement works that other websites and sources neglect to mention?

3
What is -1 in 2's complement?Oliver Charlesworth
So I guess my question wasn't specific enough. So that means that any time I do subtraction, the result will be in 2's complement which must then undergo the 2's complement operation again in order to receive an unsigned binary representation?Orren Ravid

3 Answers

1
votes

In 2's compliment 1111 is -1 (if you only have 4 bits of course)

From 1111 to its absolute value invert:

0000

and add 1

0001

0
votes

Remember that you are doing signed arithmetic.

In signed arithmetic, the 1 in the most significant bit position, or leftmost position indicates a (-) sign.

So 1111 is a negative quantity.

1111 flipped is 0000 adding 1 is 0001.

So the answer has magnitude 1 and sign (-).

2-3=-1

0
votes

When you calculate in twos complement, the result will always have to be handled as twos complement. As mentioned, the result is -1 in signed twos complement, or 15 as unsigned without overflow.

What you have to notice is that if you do subtraction with positive numbers and the result will be negative you will not get overflow. But if the result is positive there will be overflow.

This is logical: if the result is positive, it has to be smaller than the original value. The only way for an addition to result in a smaller value is to overflow. When the result is negative it will always be larger than the original when handled as unsigned (MSB will be 1 whereas original will have 0) and there is no overflow.