0
0
Embedded Cprogramming~10 mins

Setting a specific bit in a register in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set bit 3 of the register.

Embedded C
register |= (1 << [1]);
Drag options to blanks, or click blank then click option'
A3
B4
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong bit number to shift.
Forgetting to use the bitwise OR operator.
2fill in blank
medium

Complete the code to clear bit 5 of the register.

Embedded C
register &= ~([1] << 5);
Drag options to blanks, or click blank then click option'
A1
B0
Cregister
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong value instead of 1 for the mask.
Not inverting the mask before ANDing.
3fill in blank
hard

Fix 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'
A&
B^
C|
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of ^ to toggle bits.
Using &= which clears bits.
4fill in blank
hard

Fill 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'
A|
B&
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of bitwise operators.
Not inverting the mask when clearing bits.
5fill in blank
hard

Fill 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'
A|
B&
C^
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up operators for set, clear, and toggle.
Forgetting to invert the mask when clearing bits.