anonymous
anonymous

Reputation: 75

Substracting two's complement

B=01010101 A=10101010

They are already in two's complement and I have to do B - A.

I don't know what to do, because if A has a 1 it means that it's a negative number. Then the operation is B - (-A) or B + A.

But B+A=11111111 (000000001 in binary) and that doesn't seem correct.

Maybe I'm not "getting it", but I really don't know what I should be doing.

Upvotes: 0

Views: 52

Answers (1)

Vitamin05
Vitamin05

Reputation: 21

Your task is to find B-A. If A is a negative number then A = -C where C = 86 in this case. So in other words B-A = B+C (NOT B+A). You should simply calculate C from A (reverse all the single bits and then add one: 01010101+1 = 01010110) and then you sum B to the calculated number:

Considering A and B both in two's complement: I think the answer is 10101011 or -85!! Here is why:

      01010101 (-171)
  +   01010110 (86)
**=   10101011 (-85)**

Upvotes: 2

Related Questions