Originally posted by talib kaimkhani:
what is the complete procedure of for example:
-12>>3
-12 is represented as 11111111 11111111 11111111 11110100
Since >> is a signed shift, you're basically going to move all the ones to the right 3 times, replacing the ones at the left end with more 1's (to keep the sign), and losing any 1 that falls off the right end. You end up with
11111111 11111111 11111111 11111110
and, 12>>>3
00000000 00000000 00000000 00001100
This is the unsigned bit, meaning that you still move the ones to the right 3 times, but you don't add ones to the left, you keep them zeroes. All you have to worry about is moving the 1's to the right 3 times. If the one falls off the end, it's gone, resulting in:
00000000 00000000 00000000 00000001
and, -12>>>2
11111111 11111111 11111111 11110100
Same thing as above, but remember, you're not replacing the ones at the left with more ones, they become zeroes. This causes the number to lose it's sign, and results in a relatively large number.
00111111 11111111 11111111 11111101
I'll let you figure out what the resulting numbers are for each, but that's what happens with the shifting
Hope that helps some
Jason