Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does >> and >>> mean in Java? [duplicate]

Tags:

java

Possible Duplicate:
Difference between >>> and >>
What does “>>>” in java mean?

What does >> and >>> mean in Java?

Why does -1 >> 2 and -1 >>> 2 have different results?

like image 642
duobei Avatar asked Jun 29 '12 02:06

duobei


People also ask

What is the difference between >>> and >> in Java?

Difference between >> and >>> operator. Both >> and >>> are used to shift the bits towards the right. The difference is that the >> preserve the sign bit while the operator >>> does not preserve the sign bit. To preserve the sign bit, you need to add 0 in the MSB.

What does >>> mean in Java?

The >>> operator is the unsigned right bit-shift operator in Java. It effectively divides the operand by 2 to the power of the right operand, or just 2 here.

What is the use of >>> operator?

The unsigned right shift operator ( >>> ) (zero-fill right shift) evaluates the left-hand operand as an unsigned number, and shifts the binary representation of that number by the number of bits, modulo 32, specified by the right-hand operand.

What is this >>> bitwise operator in Java?

It is a binary operator denoted by the symbol ^ (pronounced as caret). It returns 0 if both bits are the same, else returns 1. Let's use the bitwise exclusive OR operator in a Java program.


1 Answers

>> is a signed right shift operator which shifts a bit pattern to the right. >>> is an unsigned right shift operator which shifts a zero into the leftmost position. Please refer to the Oracle Docs.

like image 53
JR Galia Avatar answered Sep 17 '22 15:09

JR Galia