public class MainClass {
public static void main(String[] argv) {
test(1, 2);
}
static void test(int a, int b) {
int c = a & b;
System.out.println("Result AND & " + Integer.toBinaryString(c) + " = " + c);
c = a | b;
System.out.println("Result OR | " + Integer.toBinaryString(c) + " = " + c);
c = a ^ b;
System.out.println("Result XOR ^ " + Integer.toBinaryString(c) + " = " + c);
System.out.println("Complement of " + a + " = " + Integer.toBinaryString(~a));
System.out.println("Complement of " + b + " = " + Integer.toBinaryString(~b));
}
}
Result AND & 0 = 0
Result OR | 11 = 3
Result XOR ^ 11 = 3
Complement of 1 = 11111111111111111111111111111110
Complement of 2 = 11111111111111111111111111111101