Recall & Review
beginner
What does the left shift operator (<<) do in C?
The left shift operator (<<) moves the bits of a number to the left by a specified number of positions, filling the right side with zeros. It effectively multiplies the number by 2 for each shift position.
Click to reveal answer
beginner
What happens to bits shifted out on the left side during a left shift?
Bits shifted out on the left side are discarded and lost. They do not wrap around or reappear on the right side.
Click to reveal answer
intermediate
How does the right shift operator (>>) behave for unsigned integers in C?
For unsigned integers, the right shift operator (>>) shifts bits to the right and fills the left side with zeros. This is called a logical right shift.
Click to reveal answer
intermediate
How does the right shift operator (>>) behave for signed integers in C?
For signed integers, the right shift operator (>>) usually performs an arithmetic right shift, which fills the left side with the sign bit (0 for positive, 1 for negative) to preserve the number's sign.
Click to reveal answer
advanced
What is a potential risk when shifting bits more than the width of the data type?
Shifting bits by a number equal to or greater than the width of the data type (e.g., 32 for a 32-bit int) leads to undefined behavior in C, which can cause unpredictable results.
Click to reveal answer
What does the expression (1 << 3) evaluate to in C?
✗ Incorrect
Shifting 1 left by 3 positions moves the bit to the 8's place, so the result is 8.
In C, what happens when you right shift an unsigned int by 1?
✗ Incorrect
Unsigned integers use logical right shift, filling the leftmost bit with 0.
What is the result of right shifting a negative signed integer in C?
✗ Incorrect
Signed integers usually use arithmetic right shift, filling left bits with the sign bit.
What happens if you shift an int by 32 bits on a 32-bit system?
✗ Incorrect
Shifting by the bit width or more is undefined in C.
Which operator is used for left bit shifting in C?
✗ Incorrect
The << operator shifts bits to the left.
Explain how left shift and right shift operators work in C for both signed and unsigned integers.
Think about how bits move and what fills the empty spaces.
You got /5 concepts.
What are the risks of shifting bits incorrectly in embedded C programming?
Consider what happens when shifting beyond data size or shifting signed values.
You got /4 concepts.