1

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.

4 Answers 4

8

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

Sign up to request clarification or add additional context in comments.

4 Comments

Perfect answer, thanks. why do people still vote my question down, isn't this site for asking questions?
I don't know, and I don't think they should be. I'd upvote your question if I wasn't out of upvotes for the day.
Not my downvote, but it's probably because googling "Java operators" and looking through the first few results will provide what you asked for (including examples)
Good point, but like i said in the question the "bitwise operator" wasn't good enough for me, i wanted a simple explanation and a basic exmaple..
2

This is signed right shift operator. You can look for docs here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.