Bird
0
0
DSA Cprogramming~20 mins

Bit Manipulation Basics AND OR XOR NOT Left Right Shift in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bitwise Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A4 14
B8 14
C8 12
D4 12
Attempts:
2 left
💡 Hint
Remember that & compares bits and returns 1 only if both bits are 1; | returns 1 if either bit is 1.
Predict Output
intermediate
2: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);
A1 250
B13 250
C12 250
D12 251
Attempts:
2 left
💡 Hint
XOR returns 1 when bits differ; NOT flips all bits in the byte.
Predict Output
advanced
2: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);
A-4 -64
B-4 64
C1073741820 -64
D4 64
Attempts:
2 left
💡 Hint
Right shift of negative signed integers usually fills with sign bit; left shift multiplies by powers of two.
Predict Output
advanced
2: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);
A-2
BRuntime error
CCompilation error due to format specifier mismatch
D4294967294
Attempts:
2 left
💡 Hint
Consider the bit pattern of ~1 (0xFFFFFFFE) when printed with %u (unsigned int).
🧠 Conceptual
expert
2:00remaining
Understanding Bitwise Shift on Unsigned Integers
Given unsigned int x = 1; what is the value of x after the operation x = x << 31; ?
A2147483648
B0
C1
DUndefined behavior
Attempts:
2 left
💡 Hint
Left shifting 1 by 31 bits sets the highest bit in a 32-bit unsigned integer.