0

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.

2
  • 1
    B=85, A=-86. A + B = -1. A - B = A + ~B + 1 = ? Commented Sep 20, 2015 at 23:15
  • 1
    start with some smaller examples (eg. 3 bits long) and see what happens. Commented Sep 20, 2015 at 23:18

1 Answer 1

2

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)** 
Sign up to request clarification or add additional context in comments.

2 Comments

Or in terms of an 8-bit signed value, -256+171 = -85
I have just got to that point. Nice to see I finally was thinking correctly. The problem is that the exercise asks for a 8-bit number, so I'm not sure which one is the answer. -85 is 8-bit but wrong, 171 is 9-bit but correct... @ChronoKitsune

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.