C Bitwise Operators
C Bitwise Operators
1. &
2. |
3. <<
4. &&
Copy
#include <stdio.h>
int main()
{
int a=10;
int b=2;
int c;
c=(a & b);
printf("c= %d",c);
return 0;
}
1. c= 12
2. c= 10
3. c= 2
4. c= 0
Copy
#include <stdio.h>
int main()
{
unsigned char item=0x00;
/
item |=MOBILE;
item |=LAPPY;
return 1;
}
Copy
#include <stdio.h>
int main()
{
char var=0x04;
var = var | 0x04;
printf("%d,",var);
var |= 0x01;
printf("%d",var);
return 0;
}
1. 8,9
2. 4,5
3. 8,8
4. 4,4
/
5) Predict the output of following program.
Copy
#include <stdio.h>
int main()
{
char flag=0x0f;
flag &= ~0x02;
printf("%d",flag);
return 0;
}
1. 13
2. d
3. 22
4. 10
Copy
int x = 10 ^ 2
1. 5
2. 6
3. 7
4. 8
Copy
#include <stdio.h>
/
int main()
{
int x=10;
x &= ~2;
printf("x= %d",x);
return 0;
}
1. x= 10
2. x= 8
3. x= 12
4. x= 0
8) Which Bitwise Operator can be used to check whether a number is EVEN or ODD quickly?
9) Which statement is suitable to check 3rd (count from 0) bit is high (set) or not?
10) Left shift (<<) and Right shift (>>) operators are equivalent to _____________ by 2.