There's a reason why you have to cast the result of b >>> 1 to byte: that's because the result of the expression is an
int, not a byte.
This is what happens when the expression b >>> 1 is evaluated:
1. b is widened to a 32-bit int with the value -1 (so, 32 bits that are all 1)
2. that is shifted one bit to the right without sign extension, so you'll get an int with the value 0x7fffffff
3. you're converting that back to a byte by casting, which means chopping off bits 31-8; you'll end up with a byte with all bits set to 1, which is -1
Note that bit shift operators are not on the
SCJP 5 and SCJP 6 exams (only on the SCJP 1.4 exam).
[ May 08, 2008: Message edited by: Jesper Young ]