开发者

What is >> in java? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Double Greater Than Sign (>>) in Java?

What does the following achieve ?

int num = (10-2) >> 1;

Found this very h开发者_如何学Goelpful -

What are bitwise shift (bit-shift) operators and how do they work?


Shift right. It moves all the bits of the number right by the number specified

10-2 = 8 = 1000 in binary

8 >> 1 = 1000 >> 1 = 100 in binary = 4


>> is just an operator to perform bitwise right shift


its bitwise right shift in java. it shifts all binary digits,1 place towards right and pastes a zero at the leftmost end. (10-2)=8 which is 1000 in binary, now right shifting each digit and pasting 0 at the leftmost position, it gives 0100 which equals 4.


Right shift the indicated number of bits.


http://download.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

First result on google for ">> operator java"


See the documentation here on Bitwise shift right

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜