I dont mind at all, helping other people helps me think and learn new things too.
Your right when you do the twos compliment you can't add 4, I just used that as an example, but the principle is the same, especially since you can only have 0's and 1's the actual value of 4 doesn't matter.
Lets look at your example: -53 >> 2
11111111 11111111 11111111 11001011 -53, becomes
11111111 11111111 11111111 11110010 after the shift
To find the decimal value use the twos compliment rule:
11111111 11111111 11111111 11110010
00000000 00000000 00000000 00001101 after flipping the bits.
When we add 1 to it we add the 1 to the right side bit (least significant) because it is also a 1 the result becomes a 0 and we carry a 1 to the next bit on the left. That bit is a 0 so adding 1 to it doesn't overflow and the result bit is a 1. The final answer would be:
00000000 00000000 00000000 00001110
this would be 14 in decimal so the result of your shift was -14.
When you get 13 you are probably not adding the 1. 13 is
00000000 00000000 00000000 00001101, which is the result after flipping all of the bits.
Another way of looking at carrying in binary:
Think of it this way, after you flip all the bits you have
00000000 00000000 00000000 00001101 this is 13, now you have to add 1. In decimal we know when you add one to a number the number increases. In binary it has to do the same thing. So if you have
00000000 00000000 00000000 00001101 and add 1, after you add the 1 but before you carry it over you have
00000000 00000000 00000000 00001100 this is 12, since we know the number has to increase you have to add a 1 back in somewhere. To do that you just keep moving left every 1 you see will become a 0, until you find a 0 and change it to a 1.
If that made it more confusing sorry, I tried to explain it another way, that helps for me
alot.
Dave
[This message has been edited by Dave Vick (edited July 24, 2001).]