Conditional Control Statements - BitWise Operators
Unlike other operators, bitwise operators opened bits (i.e. on binary values of on operand)
eg: let a= 12, b=10
Program:
main ( )
{
int a= 12, b = 10;
printf (“ %dn”, a&b);
printf (“ %dn”, a|b);
printf (“ %d”, a^b);
}
Output
8
14
6
If the value of a variable is right shifted one time, then its value becomes half the original value
Ones complement :
Program:
main ( )
{
int a= 20, b = 10;
printf (“ %dn”, a<<1);
printf (“ %dn”, a>>1);
printf (“ %d”, ~a);
}
Output
40
5
11
Is complement = - [ give no +1]
Eg : ~50 = - [50+1] = -51
~-50 = - [-50+1] = 49
is complement = [65535 – given no]
0 Doubts's