Google News
Bitwise Operators In C Language
Bitwise operators are used to perform operations at binary level. Decimal values are converted into binary values these operators are used for testing the bits, or shifting them right or left. These operators are not applicable to float or double. Following are the Bitwise operators with their meanings.
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise Exclusive – OR
<< Left Shift
>> Right Shift
~ Complement

Consider x=40 and y=80, binary form of these values are


x y x&y x/y x^y
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0

X<<1 means that the bits will be left shifted by one place, if we use x<<2 then ie means that the bits will be left shifted by 2 places


  Program : A program to illustrate the use of Bitwise Operators
#include <stdio.h>
int main()
    int num=212,i;
    for (i=0;i<=2;++i)
        printf(“Right shift by %d: %d\n “, i, num>>i);
     for (i=0;i<=2;++i) 
        printf(“Left shift by %d: %d\n” , i ,num<<i);    
        return 0;
Output :

Right shift by 0:212
Right shift by 1:106
Right shift by 2:53

Left shift by 0:212
Left shift by 1:424
Left shift by 2:848