Challenge - 5 Problems
Bitwise Mastery
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 snippet?
C
int a = 12; // binary: 1100 int b = 10; // binary: 1010 int c = a & b; printf("%d", c);
Attempts:
2 left
💡 Hint
Remember that bitwise AND compares each bit of two numbers and returns 1 only if both bits are 1.
✗ Incorrect
12 in binary is 1100, 10 in binary is 1010. Bitwise AND compares bits: 1100 & 1010 = 1000 (binary), which is 8 decimal.
❓ Predict Output
intermediate2:00remaining
Output of Bitwise OR Operation
What is the output of this C code?
C
int x = 5; // binary: 0101 int y = 3; // binary: 0011 int z = x | y; printf("%d", z);
Attempts:
2 left
💡 Hint
Bitwise OR returns 1 if either bit is 1.
✗ Incorrect
5 is 0101, 3 is 0011. OR operation: 0101 | 0011 = 0111 which is 7 decimal.
❓ Predict Output
advanced2:00remaining
Output of Bitwise XOR Operation
What will this C program print?
C
int a = 9; // binary: 1001 int b = 14; // binary: 1110 int c = a ^ b; printf("%d", c);
Attempts:
2 left
💡 Hint
XOR returns 1 only if bits differ.
✗ Incorrect
9 is 1001, 14 is 1110. XOR: 1001 ^ 1110 = 0111 which is 7 decimal.
❓ Predict Output
advanced2:00remaining
Result of Combined Bitwise Operations
What is the output of this code?
C
int a = 6; // binary: 0110 int b = 11; // binary: 1011 int c = (a & b) | (a ^ b); printf("%d", c);
Attempts:
2 left
💡 Hint
Calculate AND and XOR separately, then OR the results.
✗ Incorrect
a & b = 0110 & 1011 = 0010 (2), a ^ b = 0110 ^ 1011 = 1101 (13), OR: 0010 | 1101 = 1111 (15).
❓ Predict Output
expert3:00remaining
Bitwise Operation with Negative Numbers
What is the output of this C code snippet?
C
int a = -5; // in two's complement int b = 3; int c = a & b; printf("%d", c);
Attempts:
2 left
💡 Hint
Remember how negative numbers are stored in two's complement and how bitwise AND works.
✗ Incorrect
In two's complement (e.g., low 8 bits: -5 is 11111011, 3 is 00000011). Bitwise AND: 11111011 & 00000011 = 00000011 which is 3.