Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to toggle the 3rd bit of the variable flags.
Embedded C
flags = flags [1] (1 << 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using & or | instead of ^ will not toggle bits correctly.
✗ Incorrect
Using XOR (^) with a bit mask toggles the targeted bit.
2fill in blank
mediumComplete the code to toggle the least significant bit of status.
Embedded C
status [1]= 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using &= or |= will not toggle the bit.
✗ Incorrect
The ^= operator toggles the bit specified by the mask.
3fill in blank
hardFix the error in toggling the 5th bit of control.
Embedded C
control = control [1] (1 << 4);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using | sets the bit instead of toggling it.
✗ Incorrect
XOR (^) toggles the bit; using | sets it instead.
4fill in blank
hardFill both blanks to toggle the 2nd bit and check if it was set before toggling.
Embedded C
if ((flags [1] (1 << 1)) != 0) { flags [2]= (1 << 1); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using | to check bits is incorrect.
Using |= toggles incorrectly.
✗ Incorrect
Use & to check if the bit is set, then ^= to toggle it.
5fill in blank
hardFill all three blanks to toggle the 4th bit of reg only if it is currently set.
Embedded C
if (reg [1] (1 << 3)) { reg [2]= (1 << 3); result = reg [3] (1 << 3); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of & to check or read bits.
Using |= instead of ^= to toggle bits.
✗ Incorrect
Use & to check the bit, ^= to toggle it, and & to read the bit value.