What does >> do in Java?

Computers are binary devices. Because of this, numbers are represented by a sequence of 1s and 0s. Bitshifting is simply moving those sequences of 1s and 0s left or right. So all the >> operator does is shift the bits towards the right one bit. Consider the number 101: // Assuming signed 8-bit integers 01100101 … Read more

Why was 1

The relevant issue is CWG 1457, where the justification is that the change allows 1 << 31 to be used in constant expressions: The current wording of 5.8 [expr.shift] paragraph 2 makes it undefined behavior to create the most-negative integer of a given type by left-shifting a (signed) 1 into the sign bit, even though … Read more

unsigned right Shift ‘>>>’ Operator in Java [duplicate]

See http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.19 If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (ยง15.22.1) with the mask value 0x1f (0b11111). The shift distance actually used … Read more