A java blog with a collection of examples and tutorials on Java and related technologies. (Under maintenance with continuous updates)
Be in touch with java jazzle or k2java.blogspot.com.
Pages
▼
Wednesday, October 27, 2010
Bitwise Operators Summary
Integers (int and long) can be considered as collections of 32 or 64 bits.
Bitwise operators perform logical operations on each bit position, where 1 is regarded as true and zero false.
Bitwise and(a & b) - Result is 1 in every bit position where both operands have a 1.
Bitwise or(a | b) - Result is 1 only in positions where one or both operands have a 1.
Bitwise xor(a ^ b)- Result is 1 in positions where the two corresponding bits are different.
Bitwise not(~a) - Unary operator. Result is each bit of operand inverted.
Shift left(a << n) - Shifts bits n positions left. Zeros added on right.
Shift right(a >> n) - Shifts bits n positions right. High-order bit inserted on left.
Shift right(a >>> n) - Shifts bits n positions right. Zeros inserted at left.
No comments:
Post a Comment