How to use the Bitwise Logical Operators?

The following program demonstrates the bitwise logical operators:

public class Main {

  public static void main(String args[]) {

    int a = 1;

    int b = 2;

    int c = a | b;

    int d = a & b;

    int e = a ^ b;

    int f = (~a & b) | (a & ~b);

    int g = ~a & 0x0f;

 

    System.out.println(" a = " + a);

    System.out.println(" b = " + b);

    System.out.println(" a|b = " + c);

    System.out.println(" a&b = " + d);

    System.out.println(" a^b = " + e);

    System.out.println("~a&b|a&~b = " + f);

    System.out.println(" ~a = " + g);

 

  }

}