Reputation: 1243
I have looked on the oracle website, but that seems to advanced for me, please can someone give me a basic run down on what the >> operator is for in java? and maybe a basic example would be nice.
Upvotes: 1
Views: 211
Reputation: 21459
The >>
is a signed right shift. It basically takes a binary value and shifts it to the right:
Example: 8 >> 2 = 4
which in binary gives 1000 >> 2
(shift 1000
by two positions) = 10
in binary which is 2.
Upvotes: 0
Reputation: 62855
This is signed right shift operator. You can look for docs here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
Upvotes: 2
Reputation: 1023
Please find example here: http://www.roseindia.net/java/master-java/java-right-shift.shtml
Upvotes: 0
Reputation: 198481
>>
is right bitwise shift. For example, 5 >> 1
is 2
, because 5
is 101
in binary, and that's shifted right to get 10
.
It's (mostly) equivalent to "divided by two to the", although it's not quite equivalent for negative numbers.
Upvotes: 8