Challenge - 5 Problems
Bitwise Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of bitwise AND operation
What is the output of the following C code?
C
int a = 12; // binary: 1100 int b = 10; // binary: 1010 int c = a & b; printf("%d", c);
Attempts:
2 left
💡 Hint
Remember that & compares bits and returns 1 only if both bits are 1.
✗ Incorrect
12 in binary is 1100 and 10 is 1010. Bitwise AND gives 1000 which is 8 in decimal.
❓ Predict Output
intermediate2:00remaining
Output of left shift operation
What will be printed by this C code?
C
unsigned int x = 5; // binary: 0000 0101 unsigned int y = x << 2; printf("%u", y);
Attempts:
2 left
💡 Hint
Left shift by 2 means multiply by 2 twice (4 times).
✗ Incorrect
5 shifted left by 2 bits is 5 * 4 = 20.
❓ Predict Output
advanced2:00remaining
Output of toggling bits using XOR
What is the output of this C code snippet?
C
int num = 29; // binary: 0001 1101 int mask = 15; // binary: 0000 1111 int result = num ^ mask; printf("%d", result);
Attempts:
2 left
💡 Hint
XOR flips bits where mask has 1s.
✗ Incorrect
29 (00011101) XOR 15 (00001111) flips last 4 bits: 00010010 which is 18 decimal.
❓ Predict Output
advanced2:00remaining
Output of checking if a number is a power of two
What does this C code print?
C
int n = 16; int check = (n & (n - 1)) == 0; printf("%d", check);
Attempts:
2 left
💡 Hint
A power of two has only one bit set.
✗ Incorrect
For powers of two, n & (n-1) equals zero, so check is 1 (true).
❓ Predict Output
expert2:00remaining
Output of clearing the rightmost set bit
What is the output of this C code?
C
int x = 44; // binary: 0010 1100 int y = x & (x - 1); printf("%d", y);
Attempts:
2 left
💡 Hint
x & (x-1) clears the rightmost set bit.
✗ Incorrect
44 in binary is 00101100. Clearing rightmost set bit gives 00101000 which is 40.