Bitwise Operator Summary : Bitwise Operators « Operators « SCJP






Operator        Example         Result

~               ~3              -4
   
&               3 & 4           0
   
|               3 | 4           7

^               5 ^ 4           4


Operand 1        Operator         Operand 2            Result

0                &                0                    0

0                &                1                    0

1                &                0                    0

1                &                1                    1

0                |                0                    0

0                |                1                    1

1                |                0                    1

1                |                1                    1

0                ^                0                    0

0                ^                1                    1

1                ^                0                    1

1                ^                1                    0


public class MainClass {
  public static void main(String[] argv) {
    System.out.println(~3);
    System.out.println(3 & 4);
    System.out.println(3 | 4);
    System.out.println(5 ^ 4);
  }
}
-4
0
7
1








2.3.Bitwise Operators
2.3.1.Bitwise Operator Summary
2.3.2.Shift Operator Summary
2.3.3.The Bitwise Inversion Operator ~ performs bitwise inversion on integral types.
2.3.4.The Boolean Complement Operator ! inverts the value of a boolean expression.
2.3.5.The bitwise operator & provides bitwise AND
2.3.6.The bitwise operator ^ provides eXclusive-OR (XOR)
2.3.7.The bitwise operator | provides OR operations
2.3.8.Here is an example of the use of the & operator:
2.3.9.Java method to perform various bitwise operations on two integers and display the results