Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set bit 3 of the register.
Embedded C
register |= (1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong bit number to shift.
Forgetting to use the bitwise OR operator.
✗ Incorrect
Bit 3 means shifting 1 by 3 positions to the left.
2fill in blank
mediumComplete the code to clear bit 5 of the register.
Embedded C
register &= ~([1] << 5);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong value instead of 1 for the mask.
Not inverting the mask before ANDing.
✗ Incorrect
To clear bit 5, shift 1 by 5 and invert it with ~.
3fill in blank
hardFix the error in the code to toggle bit 2 of the register.
Embedded C
register [1]= (1 << 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of ^ to toggle bits.
Using &= which clears bits.
✗ Incorrect
Toggling a bit uses the XOR operator ^.
4fill in blank
hardFill both blanks to set bit 4 and clear bit 1 of the register.
Embedded C
register = (register [1] (1 << 4)) [2] ~(1 << 1);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of bitwise operators.
Not inverting the mask when clearing bits.
✗ Incorrect
Use | to set bit 4 and & with inverted mask to clear bit 1.
5fill in blank
hardFill all three blanks to set bit 7, clear bit 3, and toggle bit 0 of the register.
Embedded C
register = ((register [1] (1 << 7)) [2] ~(1 << 3)) [3] (1 << 0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up operators for set, clear, and toggle.
Forgetting to invert the mask when clearing bits.
✗ Incorrect
Set bit 7 with OR, clear bit 3 with AND and inverted mask, toggle bit 0 with XOR.