posted 19 years ago
Well, you know bytes just have 8 bits. When you shift left the right operand of the shift operator [<<] is promoted to an integer (if it is not a integer already). The right operand is not taken into account for promotion, so it could be a long and would not affect the result.
Now, if the shifted value is assigned back to a byte the upper 16 bits will be discarded.
So, in the next example, when you move the 1 bit to the left, up to the 7th position, then you turn the byte into a negative number.
Hope it helps.
[ June 18, 2005: Message edited by: Edwin Dalorzo ]