Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set bit 3 of the register.
Embedded C
REG |= (1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong bit number.
Forgetting to use parentheses around (1 << bit).
✗ Incorrect
Bit 3 is set by shifting 1 left by 3 positions.
2fill in blank
mediumComplete the code to clear bit 5 of the register.
Embedded C
REG &= ~(1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the mask.
Not negating the mask before AND operation.
✗ Incorrect
To clear bit 5, shift 1 left by 5 and invert it with ~.
3fill in blank
hardFix the error in the code to toggle bit 2 of the register.
Embedded C
REG [1]= (1 << 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using |= which sets the bit instead of toggling.
Using &= which clears bits.
✗ Incorrect
Toggle a bit using XOR (^=) with the bit mask.
4fill in blank
hardFill both blanks to check if bit 4 is set in the register.
Embedded C
if ((REG [1] (1 [2] 4)) != 0) { // bit 4 is set }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of & which always returns non-zero.
Using right shift >> instead of left shift <<.
✗ Incorrect
Use bitwise AND (&) with 1 shifted left (<<) by 4 to check bit 4.
5fill in blank
hardFill all three blanks to set bits 0, 2, and 7 in the register.
Embedded C
REG |= ([1] << 0) | ([2] << 2) | ([3] << 7);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the bit mask.
Not combining masks with OR operator.
✗ Incorrect
Set bits by shifting 1 to each bit position and OR-ing them together.