1

Hi I was wondering if anyone could help me with something I can find literally nothing online about. I was looking through some code that had the following statement:

int mainInt = 10>>> 5;

Does anyone know what this >> operator is?

For example 10 >> 1 equals 5 20 >>> equals 3

Thanks

2 Answers2

2

>> is the arithmetic right-shift operator.

>>> is the logical right-shift operator.

The first one preserves the sign of the operand. The second inserts zeros at the most significant bit positions, and is usually applied on unsigned numbers.

M A
  • 71,713
  • 13
  • 134
  • 174
2

This has already been answered: Double Greater Than Sign (>>) in Java?

The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.

You can read about it here.

Community
  • 1
  • 1
Forseth11
  • 1,418
  • 1
  • 12
  • 21