Shaun Wild
Shaun Wild

Reputation: 1243

Java - >> operator?

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

Answers (4)

GETah
GETah

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

om-nom-nom
om-nom-nom

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

Sandip Dhummad
Sandip Dhummad

Reputation: 1023

Please find example here: http://www.roseindia.net/java/master-java/java-right-shift.shtml

Upvotes: 0

Louis Wasserman
Louis Wasserman

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

Related Questions