Confused about "bitwise addition", 1's complement

AtWitsEnd

New member
Joined
Sep 15, 2008
Messages
10
I've been trying to wrap my mind around 1's & 2's complement (in computer hardware number representation schemes) and, while reviewing an explanation I came across an example I cannot follow. The example is for 1's complement bitwise addition. First, let me start with an example I CAN follow.

This makes sense to me (1's complement bitwise subtraction):

11111111
01001001
10110110

What I see, from left to right, is: 1 bit minus 1bit equals zero bits, 1 bit minus 0 bits equals 1 bit, etc.


This does NOT make sense to me (1's complement bitwise addition):

001100111
010011110
100000101

From left to right, the first operation makes sense to me: 1 bit plus zero bits equals 1 bit. The rest makes no sense to me. For some reason, in the second position 1 bit plus 1 bit equals zero bits but in the third position, 1 bit plus 1 bit equals one bit (which is exactly the opposite of the previous position which had the same bits). Then, in positions four through seven, 1 bit plus zero bits equals 0 bits (which is the exact opposite of what the operation produced in the first position which had the same bits). I understand that to finish this answer you take the ninth bit and add it back to the least significant bit. However, my problem here is that I can't see the pattern in bitwise addition that produces the answer given in the first place. Could someone out there possibly break it down for me left-bit-to-right-bit? I'm not sure what I'm missing. Am I missing a pattern of xor/nor/not/and operations or maybe these operations have nothing to do with bitwise addition? I don't know. I've put these searches into google: "bitwise addition", "explain bitwise addition" and even "bitwise addition for dummies". Nothing comes back with an explanation of just exactly what is going on here, from left-to-right, bit-for-bit. So, if someone out there has the patience for this explanation, I'd REALLY appreciate it.
 
A good way to think about this is to treat it somewhat like normal addition. When you add two numbers, say 8+2, in the ones place you have 2+8, so you put a 0 in the ones place and carry the 1 to the tens place. It is the same way in bitwise addition. 1+1 = 0 carry the 1. 1+1+1 = 1 carry the 1. In the case of 1's complement, this will be right each time.

To demonstrate your example, you see

001100111
010011110
_________
100000101

but what it really looks like with the carry bit is

11111110
001100111
010011110
_________
100000101

Remember, in binary, 2 is 10. So 1+1 = 10, carry the 1 to the next bit.
 
As a warning though, you also have to worry about overflow. In the case of your example, if the last bit in the answer was the last available bit, then you have run into overflow, where you add two positive numbers and the answer appears negative.
 
Thank you so much for posting this answer! I was just struggling with the same exact issue.

Now I understand.

Ted
 
Top