Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set bit 2 of the variable 'flags'.
Embedded C
flags [1] (1 << 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&=' clears bits instead of setting them.
Using '^=' toggles bits instead of just setting them.
✗ Incorrect
Using the OR assignment operator '|=' sets bit 2 without changing other bits.
2fill in blank
mediumComplete the code to set bits 0 and 3 of 'status' using OR.
Embedded C
status [1] (1 << 0) | (1 << 3);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' overwrites all bits, losing previous data.
Using '&=' clears bits instead of setting them.
✗ Incorrect
The '|=' operator sets bits 0 and 3 without changing other bits.
3fill in blank
hardFix the error in the code to correctly set bit 5 of 'control'.
Embedded C
control [1] 1 << 5;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' overwrites all bits, losing previous settings.
Using '&=' clears bits instead of setting them.
✗ Incorrect
Using '|=' with '1 << 5' sets bit 5 correctly.
4fill in blank
hardFill both blanks to set bits 1 and 4 of 'reg' using OR.
Embedded C
reg [1] (1 << 1 [2] 1 << 4);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of '|' to combine bits clears bits.
Using '^' toggles bits instead of setting them.
✗ Incorrect
Use '|=' to assign and '|' to combine bits 1 and 4.
5fill in blank
hardFill all three blanks to set bits 0, 2, and 7 of 'flags' using OR.
Embedded C
flags [1] (1 [2] 1 << 2 [3] 1 << 7);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' clears bits instead of setting them.
Using '^' toggles bits instead of setting them.
✗ Incorrect
Use '|=' to assign and '|' to combine multiple bits to set bits 0, 2, and 7.