0
votes

I've built a four bit adder/subtractor utilizing 4, 1 bit full adders and the input and output are twos complement numbers.

If X=0111 and Y=1000 their sum is obviously 1111.

In decimal this is equivalent to 7 + 8 thus 15 which is what the sum results in.

I am confused however if this result needs to be translated back into "regular" binary by flipping the bits and adding one? So that the answer would be 0001 representing 1 in decimal instead. And that Y in decimal before translation was actually 0110 representing 6 thereby yielding the following in binary 7-6 = 1. If anyone could point me in the right direction I would appreciate it!

1

1 Answers

1
votes

It appears you've got the conversion for Y wrong. Y = 10002 = -810.

To represent -6 you take 0110, flip the bits to get 1001 and add one, so Y = 1010. (And 0111 + 1010 = 0001 as you expect.)

To go back, flip the bits of 1010 = 0101 and add one giving 0110 = 6.

Edit to answer your follow-up question:

Let:

X = 0111
Y = 1100

X + Y = 0011 (ignoring overflow)

So whatever we're adding, it equals 3. We know that X = 7.

Y = 1100 => 0011 + 1 = (negative)0100 = -4

7 + (-4) = 3

No translation is necessary, just represent the positive and negative numbers correctly. I think your confusion is coming from the fact that we're "negating" the negative numbers to find the absolute value of that number and sticking a negative sign in front of it, as in the conversion of Y above. That's because negative numbers in 2's complement aren't as readable as positive numbers, but 0100 is still +4 and 1100 is still -4.