How to
if (x == 1) printf("2\n");
else if (x == 2) printf("1\n");
else printf("0\n");
using bitwise operators?
My attempt is:
for (x = 0; x < 8; x++) {
printf("%d\n", 0x03 & (0x03 ^ x));
}
Output:
3
2
1
0
3
2
1
0
Desired output:
0
2
1
0
0
0
0
0
printf("%d\n", x & 0xfc || !x ? 0 : 3 - x & 3);should do the job.x = 0