Discussion in 'General Electronics Chat' started by bob800, Aug 14, 2012.

1. ### bob800 Thread Starter Active Member

Dec 10, 2011
50
3
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 . 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

File size:
9.7 KB
Views:
60
2. ### Papabravo Expert

Feb 24, 2006
11,868
2,523
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).
Code ( (Unknown Language)):
1.
2. 1111 = -8 + 4 + 2 + 1 = -1
3. 1110 = -8 + 4 + 2 + 0 = -2
4. ...
5. and so forth
6.

Last edited: Aug 14, 2012
3. ### bob800 Thread Starter Active Member

Dec 10, 2011
50
3
*facepalm*

OK this is what I was fundamentally missing (aside from common sense)! Thank you for clearing this up!

4. ### Papabravo Expert

Feb 24, 2006
11,868
2,523
'saright. Once upon a time I was where you are now.

5. ### WBahn Moderator

Mar 31, 2012
23,576
7,214
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.