All information stored in our computer is stored as binary value.
Bitwise OR
If the value of two binary bits is '0' then the value of the result is '0' and if any one of the two bits is '1' then the value of the result is '1'.
int main()
{
int x=10,y=12;
int z=x|y;
printf("z=%d",z);
}
Description:
A memory is created for variable x and y in which value 10 is stored for x and value 12 for y.
Binary value of 10:10 10
Binary value of 12 is :11 00
z=x \y;
OR operation is performed on x and y and the value 1110 is stored in z.
The integer value of 1110 = 14.
Bitwise AND
If the value of two binary bits is "1", then the value of the result is "1" and if any of the two bits is "0", then the value of the result is "0".
int main()
{
int x=5,y=9;
int z=x&y;
printf("Value of z=%d",z);
return 0;
}
output:
1
one's complement
It is a Unary operator. Here if the value of bit is "1" it will be changed to "0" and if it is 0" it will be changed to "1".
int main()
{
int x=4;
printf(“value=%d”,x);
return 0;
}
output:
-5
Left shift operator
The left shift operator is used to shift a binary bit sequence to the left.
int main()
{
int x=2;
printf(“value=%d”,x<<1);
return 0;
}
output:
4
Right shift operator
The right shift operator is used to shift a binary bit sequence to the right.
int main()
{
int x=128;
printf(“value=%d”,x>>1);
return 0;
}
output:
64
XOR operator
If the value of two binary bits is the same value then the value of the result is stored as "0" and if the value of the bit is different then the value of the result is stored as "1".
int main()
{
int x=5,y=9;
int z=x^y;
printf(“value=%d”,z);
return 0;
}
output:
12