2012-07-07 21 views

答えて

6

最初の演算子は符号ビットのコピーをシフトして値を符号拡張します。第2のものは常にゼロにシフトする。

これは、ビット演算を行う目的で符号なし整数をエミュレートし、Javaで符号なし整数型が不足していることを部分的に補うためです。

11

>>は、Java tutorialで説明されているように、右シフトの算術(符号付き)で、>>>は論理(符号なし)右シフトです。それらを負の値で試してみると、違いが見えます。

3

This explains it really well。その同じページには簡略exampleもあります。

しかし、本当の簡単な要約について:

<< signed left shift - shifts a bit pattern to the left 
    0 0 1 1 1 => 0 1 1 1 0 

>> signed right shift - shifts a bit pattern to the right 
    0 0 1 1 1 => 0 0 0 1 1 

>>> unsigned right shift - shifts a zero into the leftmost position 
    1 1 1 0 => 0 0 1 1 

~ unary bitwise complement operator 
    A | Result 
    0 | 1 
    1 | 0 
    0 | 1 
    1 | 0 

& bitwise and 
    A | B | Result 
    0 | 0 | 0 
    1 | 0 | 0 
    0 | 1 | 0 
    1 | 1 | 1 

^ xor 
    A | B | Result 
    0 | 0 | 0 
    1 | 0 | 1 
    0 | 1 | 1 
    1 | 1 | 0 

| inclusive or 
    A | B | Result 
    0 | 0 | 0 
    1 | 0 | 1 
    0 | 1 | 1 
    1 | 1 | 1 
関連する問題