Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, November 19, 2007

java Bitwise Operators

Bitwise operators operate on bits of ints. Result is int.
i & jBits are "anded" - 1 if both bits are 1. 5 & 3 is 1.
i | jBits are "ored" - 1 if either bit is 1. 5 | 3 is 7.
i ^ jBits are "xored" - 1 if bits are different. 5 ^ 3 is 6.
~iBits are complemented (0 -> 1, 1 -> 0)
i <<>Bits in i are shifted j bits to the left, zeros inserted on right. 5 <<>
i >> jBits in i are shifted j bits to the right. Sign bits inserted on left. 5 >> 2 is 1.
i >>> jBits in i are shifted j bits to the right. Zeros inserted on left.

No comments:

Post a Comment

Archives