Adder-Subtractors and 2's compliment

Thread Starter

bob800

Joined Dec 10, 2011
50
Hello,

After learning about digital adder-subtractors, I thought I would play around with a simulator to confirm my understanding: (http://teahlab.com/4-bit_Adder_Subtractor/)

Unfortunately, this only made it more confusing :D. While everything makes sense with sums of 0 or higher, I'm having a hard time understanding how negative numbers are represented.

Take a look at my attached screenshot, for instance. Everything in blue represents a LOW state, while everything in red represents a HIGH state; hence, the simulator is in "subtractor" mode with the "B2" input HIGH and all other inputs LOW.

Now if I'm understanding this, I should be subtracting 4 from 0, in which case the "sum" would be negative. My limited knowledge of digital arithmetic tells me that negative numbers are represented in the "2's complement" form, with the MSB representing the sign (+ or -). So:

0100 = 4
1011 = 1's compliment
1100 = 2's compliment

But reading from the top down, the simulator is outputting "0011"! Could someone please explain where my logic fails?!

Thanks,

bob800
 

Attachments

Papabravo

Joined Feb 24, 2006
22,084
Everything is as it should be. A0 and B0 at the TOP of your diagram are the least significant bits. A3 and B3 at the BOTTOM of your diagram are the most significant bits.

When 1100 is read right to left it is 0011 and vice versa. Get it?

BTW it is an error to consider the MSB as just a sign bit in 2s complement notation. It is both a sign bit and a magnitude bit. It is also correct to assign it a negative magnitude (e.g. -8, in the case of 4 bit numbers).
Rich (BB code):
1111 = -8 + 4 + 2 + 1 = -1
1110 = -8 + 4 + 2 + 0 = -2
...
and so forth
 
Last edited:

Thread Starter

bob800

Joined Dec 10, 2011
50
When 1100 is read right to left it is 0011 and vice versa. Get it?
*facepalm*

BTW it is an error to consider the MSB as just a sign bit in 2s complement notation. It is both a sign bit and a magnitude bit. It is also correct to assign it a negative magnitude (e.g. -8, in the case of 4 bit numbers).
OK this is what I was fundamentally missing (aside from common sense)! Thank you for clearing this up!
 

WBahn

Joined Mar 31, 2012
32,944
*facepalm*
Take a moment and consider that you said that everything made sense for positive sums. But if you were reading the output in reverse order, that doesn't make sense. You should have been interpretting any odd-valued sum as a negative number!

Be sure you understand why you thought you were seeing what you thought you expected for positive sums in light of this.
 
Top