Course Content
Programming in C
About Lesson

Bitwise operators can be used for bit manipulation on integral operands (char, short, int and long), both signed and unsigned.

&bitwise AND
|bitwise inclusive OR
^bitwise exclusive OR (XOR)
<<left shift
>>right shift
~one's complement (unary)

It’s important to distinguish the bitwise operators & and | from the logical operators && and ||, which imply and left to right evaluation of a truth value. For example, if x is 1 and y is 2, then x & y is 0 (In binary representation, 1 is 01 and 2 is 10, so if you do bitwise AND, it will be 00), while x && y is 1.

The shift operators (<< and >>) perform left and right shifts of their left operand by the number of bit positions given by the right operand.

int x = 2;
x = x << 1;

Here, x << 1 shifts all the bits of x left by 1, filling the vacated bit with zero. So, x will become 4.

Scroll to Top