posted 17 years ago
When performing a shift, only a portion of the right-side operand is used. When shifting an int, only the right-most 5 bits of the shift value; therefore, the number of bits shifted will always fall within the range of 0 and 31. When shifting a long, only the right-most 6 bits of the shift value are used; therefore, the shift range falls within 0 and 63.
-4 in binary is 1111 1111 1111 1111 1111 1111 1111 1100. Since you are shifting an int, only the right-most 5 bits are used. The 5 right most bits in -4 are 11100, which evaluates to 28.