Bitwise Operators

Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte.

 

Bitwise operator works on bits and performs bit-by-bit operation.

 

Assume if 

int a = 60;

int b = 13;

 

Now in binary format they will be as follows.

 

a

operator

b

=

0011

&

1100

0000 1100

0011

|

1100

0011 1101

0011

^

1100

0011 0001

0011

~

1100

1100 0011