From http://www.cnblogs.com/ggjucheng/archive/2012/12/15/2820012.html
English from http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
JavaProgramThe language provides bitwise AND shift operations for integer types. The operators discussed below are rarely used. The purpose of this chapter is clear to let you know the existence of these operators.
Bitwise complement operator "~" for one dollar It can be used for any integer to change each 0 to 1, and each 1 to 0. for example, byte A contains eight digits. If the bitwise mode is "00000000", this operator is used to change to "11111111 ".
Signed left shift operator"<
", Move the bit to the left, with the symbol">
", Move to the right. The bitwise mode is the operand of the left side, and the number of moving locations is the operand of the right side.
Unsigned right shift operator">>>
"Move 0 to the leftmost, but for the signed left shift operator">", The leftmost digit depends on the corresponding symbol extension (NOTE: For positive numbers, the leftmost digit is 1, and the leftmost digit is 1 after the shifted symbol is left, the value of the unsigned left shift to the rightmost is 0 ).
By bit&
Operator to perform a bitwise AND OPERATION
The bitwise ^ operator executes an bitwise XOR operation.
Bitwise | the operation executes a bitwise AND operation.
The following program,Bitdemo: outputs number "2" to standard output by bit and operation.
Class bitdemo {public static void main (string [] ARGs) {int bitmask = 0x000f; int val = 0x2222; // prints "2" system. out. println (Val & bitmask );}}