Challenge - 5 Problems
Bitwise Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Bitwise AND and OR Operations
What is the output of the following C code snippet?
DSA C
int a = 12; // binary: 1100 int b = 10; // binary: 1010 int c = a & b; int d = a | b; printf("%d %d", c, d);
Attempts:
2 left
💡 Hint
Remember that & compares bits and returns 1 only if both bits are 1; | returns 1 if either bit is 1.
✗ Incorrect
12 in binary is 1100, 10 is 1010.
AND: 1100 & 1010 = 1000 (8 decimal)
OR: 1100 | 1010 = 1110 (14 decimal)
❓ Predict Output
intermediate2:00remaining
Result of Bitwise XOR and NOT Operations
What will be printed by this C code?
DSA C
unsigned char x = 5; // binary: 00000101 unsigned char y = 9; // binary: 00001001 unsigned char z = x ^ y; unsigned char w = ~x; printf("%u %u", z, w);
Attempts:
2 left
💡 Hint
XOR returns 1 when bits differ; NOT flips all bits in the byte.
✗ Incorrect
5 (00000101) XOR 9 (00001001) = 00001100 (12 decimal)
NOT 5 flips bits: 11111010 (250 decimal for unsigned char)
❓ Predict Output
advanced2:00remaining
Left and Right Shift Effects on Signed Integers
What is the output of this C code snippet?
DSA C
int a = -16; // binary (32-bit): 11111111 11111111 11111111 11110000 int b = a >> 2; int c = a << 2; printf("%d %d", b, c);
Attempts:
2 left
💡 Hint
Right shift of negative signed integers usually fills with sign bit; left shift multiplies by powers of two.
✗ Incorrect
Right shift -16 by 2: -16 / 4 = -4 (arithmetic shift)
Left shift -16 by 2: -16 * 4 = -64
❓ Predict Output
advanced2:00remaining
Output with Mismatched Format Specifier on Bitwise NOT
What is the output of the following C code snippet? (Note: may produce compiler warning)
DSA C
int x = 1; int y = ~x; printf("%u", y);
Attempts:
2 left
💡 Hint
Consider the bit pattern of ~1 (0xFFFFFFFE) when printed with %u (unsigned int).
✗ Incorrect
~1 produces 0xFFFFFFFE, which is -2 as signed int but 4294967294 as unsigned int.
%u expects unsigned int, leading to this output (with compiler warning).
🧠 Conceptual
expert2:00remaining
Understanding Bitwise Shift on Unsigned Integers
Given unsigned int x = 1; what is the value of x after the operation x = x << 31; ?
Attempts:
2 left
💡 Hint
Left shifting 1 by 31 bits sets the highest bit in a 32-bit unsigned integer.
✗ Incorrect
1 shifted left 31 bits becomes 2^31 = 2147483648.
For unsigned int, this is well-defined.
