Loading, please wait...

Bitwise Operators

Bitwise operators perform manipulations of data at the bit level. These operators also perform shifting of bits from right to left. Bitwise operators are not applied to float or double.

 

x

y

x &y

x|y

x^y

0

0

0

0

0

0

1

0

1

1

1

1

1

1

0

1

0

0

1

1

 

Operator

Description

&    bitwise AND

The bits in the result are set to 1 if the corresponding bits in the two operands are both 1.

|      bitwise inclusive OR

The bits in the result are set to 1 if at least one of the corresponding bits in the two operands is 1.

^     bitwise exclusive OR

The bits in the result are set to 1 if exactly one of the corresponding bits in the two operands is 1.

~     left shift

Shifts the bits of the first operand left by the number of bits specified by the second operand; fill from the right with 0 bits.

<<   right shift

Shifts the bits of the first operand right by the number of bits specified by the second operand; the method of filling from the left is machine dependent

>> one ’s complement

All 0 bits are set to 1 and all 1 bits are set to 0.

 

Example

num1 = 0001000
num2=2
num1 << num2 =0100000
num1 >> num2 = 0000010