0
0
Embedded Cprogramming~10 mins

Register bit manipulation patterns 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
REG |= (1 << [1]);
Drag options to blanks, or click blank then click option'
A3
B2
C4
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong bit number.
Forgetting to use parentheses around (1 << bit).
2fill in blank
medium

Complete the code to clear bit 5 of the register.

Embedded C
REG &= ~(1 << [1]);
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the mask.
Not negating the mask before AND operation.
3fill in blank
hard

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

Fill 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'
A&
B|
C<<
D>>
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of & which always returns non-zero.
Using right shift >> instead of left shift <<.
5fill in blank
hard

Fill 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'
A1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the bit mask.
Not combining masks with OR operator.