Bitwise Operators in C


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,

Example

 Live Demo

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

Output

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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

360 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements