Java Program To Demonstrate Bitwise Operators

Java Program To Demonstrate Bitwise Operators

Write Java program to demonstrate the use of bitwise operators

// WAP to demonstrate the use of bitwise operator

public class BitwiseOperator
{
    public static void main(String[] args)
    {
        int a = 7,b = 5;

        System.out.println("Bitwise AND : 7 & 5 = "+(a&b));

        System.out.println("Bitwise OR : 7 | 5 = "+(a|b));

        System.out.println("Bitwise XOR : 7 ^ 5 = "+(a^b));

        System.out.println("Bitwise COMPLEMENT : ~7 = "+(~a));

        System.out.println("Right Shift : 7 >> 2 = "+(a>>2));

        System.out.println("Left Shift : 7 << 2 = "+(a<<2));    
    }
}

Output: