Logical Bitwise Operators

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

//Program to use Logical Bitwise Operators

class BitwiseOperatorExample

public static void main(String args[ ])

int a = 3, b = 6, c;

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

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

c = a & b;

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

c = a | b;

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

c = a ^ b;

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

c = ~b;

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

c = a << 3;

System.out.println("a << 3 = " + c);


c = b >> 2;

System.out.println("b >> 2 = " + c);

a = -1

c = a >>> 24;

System.out.println("a >>> 24 = " + c);

Output:

a=3

b=6

a&b=2

a|b=7

a^b=5

~ b = -7

a << 3 = 24

b >> 2 = 1

a >>> 24 = 255

You might also like