I was wondering how on this page:
http://www.allaboutcircuits.com/vol_4/chpt_2/3.html
011
could be -5?
http://www.allaboutcircuits.com/vol_4/chpt_2/3.html
011
could be -5?
It is twos compliment without the sign-bit explicitly specified: so in twos compliments -5 is 1011 - Understand why? The MSB '1' is the specified negative bit - so see it as (1)011 where (1) means negative and 011 means 5. If you read the article in context it is merely describing the idea of bit-flipping and adding one for going from 5 (101) to -5 (011) without the complication (as if there is any) of the sign-bit; naturally the bit-flipping and adding one works with the sign-bit too.I was wondering how on this page:
http://www.allaboutcircuits.com/vol_4/chpt_2/3.html
011
could be -5?
In unsigned binary, yes.011 is 3 though?
No, 1011 in twos compliment is -5. Would you like an explanation as to why?1011 is negative 3.
To understand how 011 becomes -5 you need to look at the following section from the e-book:How do you make -5 - sorry still can;t see it.
zero 0000
positive one 0001 negative one 1111
positive two 0010 negative two 1110
positive three 0011 negative three 1101
positive four 0100 negative four 1100
positive five 0101 negative five 1011
positive six 0110 negative six 1010
positive seven 0111 negative seven 1001
. negative eight 1000
So do the bit-flip and add one to the twos compliment, and then apply the appropriate sign-bit, where '0' = positive and '1' = negative."Note that the negative binary numbers in the right column, being the sum of the right three bits' total plus the negative eight of the leftmost bit, don't "count" in the same progression as the positive binary numbers in the left column. Rather, the right three bits have to be set at the proper value to equal the desired (negative) total when summed with the negative eight place value of the leftmost bit.
Those right three bits are referred to as the two's complement of the corresponding positive number."
The way to think about this is to look at the value of each bit placing for twos compliment; consider 4-bits xxxx, from the left:Thanks Dave
I think for me the easiest way to keep this in my head is to see the MSB, the 1, as the value which the sum of the other bits (which can total a maximum of 1 less than the value in the MSB), take away from themselves to give a necessarily negative result. This is "excess notation", I believe, is it not?
Two's complement is pretty counterintuitive, but what it has going for it is that if you add 5 and -5 you get 0, exclusive of an overflow in a bit higher than you care about. Dave might have mentioned this, but if he did I missed it in my quick glance.Thanks Dave
I think for me the easiest way to keep this in my head is to see the MSB, the 1, as the value which the sum of the other bits (which can total a maximum of 1 less than the value in the MSB), take away from themselves to give a necessarily negative result. This is "excess notation", I believe, is it not?
Decimal Binary
5 0101
-5 1011
--- -----
0 (1)0000
I didn't mention that Mark, so thanks for adding your part.Two's complement is pretty counterintuitive, but what it has going for it is that if you add 5 and -5 you get 0, exclusive of an overflow in a bit higher than you care about. Dave might have mentioned this, but if he did I missed it in my quick glance.