Difference between >>> and >>
java, operators, syntax
Solution
`>>` is arithmetic shift right, `>>>` is logical shift right.
In an arithmetic shift, the sign bit is extended to preserve the signedness of the number.
For example: -2 represented in 8 bits would be `11111110` (because the most significant bit has negative weight). Shifting it right one bit using arithmetic shift would give you `11111111`, or -1. Logical right shift, however, does not care that the value could possibly represent a signed number; it simply moves everything to the right and fills in from the left with 0s. Shifting our -2 right one bit using logical shift would give `01111111`.
Problem
What is the difference between `>>>` and `>>` operators in Java?
Related problems
- How do I perform an unsigned right shift (>>> in Java) in C/C++?
- Is shifting bits faster than multiplying and dividing in Java? .NET?
- Java's >> versus >>> Operator?
- why is 1>>32 == 1?
- Right Shift to Perform Divide by 2 On -1
- What's the reason high-level languages like C#/Java mask the bit shift count operand?
- Difference between >>> and >> operators
- What is the difference between the Java operators >> and >>>?