Java's >> versus >>> Operator?

bit-manipulation, java, operators

Solution

`>>>` is logical shift, `>>` is arithmetic shift.

- `0xDEADBEEF >>> 8` ⇒ `0x00DEADBE` (logical shift, the one you want)

- `0xDEADBEEF >> 8` ⇒ `0xFFDEADBE` (arithmetic shift)

Problem

I'm without my Java reference book and I'm having a tough time finding an answer with Google. What is the difference between the ">>" and ">>>" operators in Java? ``` int value = 0x0100; int result = (value >> 8); System.out.println("(value >> 8) = " + result); // Prints: "(value >> 8) = 1" result = (value >>> 8); System.out.println("(value >>> 8) = " + result); // Prints: "(value >>> 8) = 1" ```

Original source

Related problems