Bitwise Operators in C

CProgrammingServer Side Programming

Bitwise operators are used to perform bit-level operations on two variables. Here is the table of bitwise operators in C language,

OperatorsName of Operators
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise complement
<<Shift left
>>Shift right

Here is an example of bitwise operators in C language,


 Live Demo

#include <stdio.h>
int main() {
   int x = 10;
   int y = 28;
   int i = 0;
   printf("Bitwise AND : %d\n", x&y);
   printf("Bitwise OR : %d\n", x|y);
   printf("Bitwise XOR : %d\n", x^y);
   printf("Bitwise Complement : %d,%d\n", ~x,~-y);
   printf("Right shift by %d: %d\n", i, x>>i);
   printf("Left shift by %d: %d\n", i, y<<i);
   return 0;


Bitwise AND : 8
Bitwise OR : 30
Bitwise XOR : 22
Bitwise Complement : -11,27
Right shift by 0: 10
Right shift by 1: 5
Left shift by 2: 112
Left shift by 3: 224
Published on 08-Oct-2018 06:05:59