I recently used the shift operators in Java and noticed that the >>
operator does not have the same meaning as >>
in C. In Java >>
is Signed shift that keeps the first bit at the same value. In Java the equivalent to C shift is the >>>
operator. The left shift operator (<<
) is the same as in C and just shifts ignoring the first bit.
The things I wondered are
- Why make this change?
- Why is the notation not consistent so >> and << are signed shift and >>> and <<< are unsigned?
- Is there any use for a signed shift operator?