0
0
Embedded Cprogramming~20 mins

Left shift and right shift behavior in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shift Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A8
B16
C0
D1
Attempts:
2 left
💡 Hint
Left shifting by 3 bits multiplies the number by 2^3.
Predict Output
intermediate
2: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);
A0
B1073741820
C-1
D-4
Attempts:
2 left
💡 Hint
Right shift on signed negative integers usually fills with sign bit (arithmetic shift).
Predict Output
advanced
2: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);
A4294967295
B0
C2147483648
D1
Attempts:
2 left
💡 Hint
Left shifting the highest bit moves it out of the 32-bit range.
Predict Output
advanced
2: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);
A0
B1
CUndefined behavior
D2
Attempts:
2 left
💡 Hint
Shifting by more than or equal to the bit width results in zero for unsigned types.
🧠 Conceptual
expert
2:00remaining
Difference between logical and arithmetic right shift
Which statement correctly describes the difference between logical and arithmetic right shift in C?
ALogical right shift fills with zeros; arithmetic right shift fills with the sign bit.
BLogical right shift fills with the sign bit; arithmetic right shift fills with zeros.
CBoth logical and arithmetic right shifts fill with zeros regardless of sign.
DBoth logical and arithmetic right shifts fill with the sign bit regardless of sign.
Attempts:
2 left
💡 Hint
Think about how negative numbers behave when shifted right.