What is the difference between operator >> and operator >>> in java?

I used the → operator for the right offset. Now I just replaced it with →> and found the same result. Therefore, I cannot understand whether these two are fundamentally equal or not.

+5
source share
3 answers

The first character of the operator - expands the value by shifting a copy of the sign bit; the second is always shifted to zero.

The reason for this is to emulate unsigned integers to perform bit operations, partially compensating for the absence of unsigned integral types in Java.

+6
source

>> () , >>> ( ) , Java. , .

+11

This explains it very well . There is also a brief example on the same page .

But for a real brief summary:

<< signed left shift - shifts a bit pattern to the left
  0 0 1 1 1 => 0 1 1 1 0

>> signed right shift - shifts a bit pattern to the right
   0 0 1 1 1 => 0 0 0 1 1 

>>> unsigned right shift - shifts a zero into the leftmost position
  1 1 1 0 => 0 0 1 1

~ unary bitwise complement operator
  A | Result
  0 | 1
  1 | 0
  0 | 1
  1 | 0

& bitwise and
  A | B | Result
  0 | 0 | 0
  1 | 0 | 0
  0 | 1 | 0
  1 | 1 | 1

^ xor
  A | B | Result
  0 | 0 | 0
  1 | 0 | 1
  0 | 1 | 1
  1 | 1 | 0

| inclusive or
  A | B | Result
  0 | 0 | 0
  1 | 0 | 1
  0 | 1 | 1
  1 | 1 | 1
+3
source

All Articles