10

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?

Community
  • 1
  • 1
duobei
  • 101
  • 1
  • 4
  • Signed and unsigned shift right. – Hot Licks Jun 29 '12 at 02:48
  • 3
    I should note, this was a nice and concise question that was reasonably well formatted. All-around good first question. Unfortunately, this question has been asked before, so I'm voting to close the question as a duplicate. I think it's worthwhile for you to read the [faq] if you haven't already (or at least [editing-help](http://stackoverflow.com/editing-help/) for some markdown tips). – zzzzBov Jun 29 '12 at 02:53
  • Thanks, I'd check it and read the faq. – duobei Jun 29 '12 at 03:03

2 Answers2

10

>> 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.

JR Galia
  • 17,229
  • 19
  • 92
  • 144
  • 12
    Good answer, but consider answering with an example instead of just pointing to one. I personally prefer seeing an example over clicking a link to see one. – Jon Egeland Jun 29 '12 at 02:49
7

In java, there are 2 types of right shifts. >>> will attach 0's to fill the empty spaces for both positive and negative numbers (logical shift right) while >> will attach 1's if negative and 0's if positive (sign extension).

Dhruv Gairola
  • 9,102
  • 5
  • 39
  • 43