posted 20 years ago
Hi Mansi,
It helps to practice with converting decimals of all bases into binary first of all. Hope, you know ways of converting numbers. Most used numbers like -128,127,-1, Integer.MAX_VALUE and Integer.MIN_VALUE is nice to learn by heart, at least, their hex and binary representation. When doing signed right shift, you divide the original number by 2 to the power of bits to shift and take the int portion, unless that number is multiple of 32 (or 64 for long numbers). 51>>2 = 0011 0011 >> 2= 0000 1100 = 12
Left shift - you multiply the original number by 2 to the power of shifted bits (unless it's multiple of 32 or 64). Unsigned right shift is a bit trickier for negative numbers - it may result in big positive numbers:
The result is 2147483647.