Bytes are 8 bit signed integers, so when you cast the first binary number to byte
, the first bit is interpreted as the sign, therefore it's interpreted as -127
.
You can solve this by using System.out.println((byte)(0b10000000 >> 6));
(casting after the shift).
I know that passing in an uncasted byte...
Erm, 0b...
does not mean "byte;" it means "binary." You are not passing in an uncasted byte at all. (Your binary literal does fit in a byte, but it's interpreted as an int.)