BITWISE OPERATOR by Sharin Aloma:-: Below
BITWISE OPERATOR by Sharin Aloma:-: Below
OPERATOR MEANING
~ One’s compliment
>> Right shift
<< Left shift
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
These operators can operate upon ints and chars
but not on floats and doubles. Before moving on to
the details of the operators, let us first take a look at
the bit numbering scheme in integers and
characters. Bits are numbered from zero onwards,
increasing from right to left as shown:
7 6 5 4 3 2 1 0
Characters
Bitwise OR Operator:
Another important bitwise operator is the OR
operator which is represented as |.The rules that
govern the value of the resulting bit obtained after
ORing of two bits is shown in the truth table below:
Bitwise XOR Operator:
The XOR operator is represented as ^ and is also
called an Exclusive OR operator.The OR operator
returns 1,when any one of the two bits or both the
bits are 1,whereas XOR returns 1 only if one of the
two bits is 1.The truth table for the XOR operator is
given below:
^ 0 1
0 0 1
1 1 0
#include<stdio.h>
#include<conio.h>
Void main()
{
Int b=50;
b=b^12;
printf(“\n%d”,b); /*this will print 62*/
b=b^12;
printf(“\n%d”,b);/*this will print 50*/
getch();
}