bit shifting
arithmetic shift
left brings in zeroes
right brings in more of the sign bit
logical shift
left brings in zeroes
right brings in zeroes
C
<< and >> are logical for unsigned vars, arithmetic for signed vars
(actually >> for signed vars is machine dependent. the above is my linux machine and also the mac, I think.)
Java
only has signed vars, so sensibly defines << and >> as arithmetic shifts
>>> does logical right shift
logical left shift = arithmetic left shift = <<
casting byte to int maintains the sign bit, so use (b & 0xFF) for a byte b.