Java Tutorials - Java Bitwise Operators

A bitwise operator allows you to perform bit manipulation in data.

Operator

Use

Operation

>>

numA>>numB

shift bits of numA right by distance numB

<<

numA<<numB

shift bits of numA left by distance numB

&

numA&numB

bitwise and

|

numA|numB

bitwise or

^

numA^numB

bitwise Xor

~

~numA

bitwise complement


The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.

java logical operators tutorial