Challenge - 5 Problems
Shift Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of left shift on unsigned integer
What is the output of this C code snippet when compiled and run on a typical 32-bit system?
Embedded C
unsigned int x = 1; unsigned int y = x << 3; printf("%u", y);
Attempts:
2 left
💡 Hint
Left shifting by 3 bits multiplies the number by 2^3.
✗ Incorrect
Left shifting 1 by 3 bits moves the bit pattern 3 places to the left, resulting in 8.
❓ Predict Output
intermediate2:00remaining
Right shift on signed negative integer
What is the output of this C code snippet on a system where right shift of signed integers is arithmetic?
Embedded C
int x = -16; int y = x >> 2; printf("%d", y);
Attempts:
2 left
💡 Hint
Right shift on signed negative integers usually fills with sign bit (arithmetic shift).
✗ Incorrect
Arithmetic right shift divides by powers of two rounding toward negative infinity, so -16 >> 2 is -4.
❓ Predict Output
advanced2:00remaining
Behavior of left shift causing overflow
What is the output of this C code snippet on a 32-bit unsigned integer?
Embedded C
unsigned int x = 0x80000000; unsigned int y = x << 1; printf("%u", y);
Attempts:
2 left
💡 Hint
Left shifting the highest bit moves it out of the 32-bit range.
✗ Incorrect
Shifting 0x80000000 left by 1 bit discards the highest bit, resulting in 0.
❓ Predict Output
advanced2:00remaining
Right shift on unsigned integer with large shift count
What is the output of this C code snippet on a 32-bit unsigned integer?
Embedded C
unsigned int x = 1; unsigned int y = x >> 33; printf("%u", y);
Attempts:
2 left
💡 Hint
Shifting by more than or equal to the bit width results in zero for unsigned types.
✗ Incorrect
Right shifting 1 by 33 bits on a 32-bit unsigned integer results in 0 because bits shifted out are lost.
🧠 Conceptual
expert2:00remaining
Difference between logical and arithmetic right shift
Which statement correctly describes the difference between logical and arithmetic right shift in C?
Attempts:
2 left
💡 Hint
Think about how negative numbers behave when shifted right.
✗ Incorrect
Logical right shift always fills with zeros; arithmetic right shift preserves the sign by filling with the sign bit.