0
0
Embedded Cprogramming~10 mins

Clearing 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 clear bit 3 of the variable reg.

Embedded C
reg = reg & [1];
Drag options to blanks, or click blank then click option'
A1 << 3
B1 >> 3
C~(1 >> 3)
D~(1 << 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR instead of AND.
Not inverting the mask before AND.
Shifting bits in the wrong direction.
2fill in blank
medium

Complete the code to clear the bit specified by bit_pos in reg.

Embedded C
reg &= [1];
Drag options to blanks, or click blank then click option'
A~(1 << bit_pos)
B~(1 >> bit_pos)
C1 >> bit_pos
D1 << bit_pos
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to invert the mask.
Using OR instead of AND.
Shifting bits in the wrong direction.
3fill in blank
hard

Fix the error in the code that attempts to clear bit 2 of reg.

Embedded C
reg = reg & [1];
Drag options to blanks, or click blank then click option'
A1 << 2
B~(1 << 2)
C~(1 >> 2)
D1 >> 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using a mask without inversion.
Shifting bits right instead of left.
Using OR instead of AND.
4fill in blank
hard

Fill both blanks to clear bit 5 in reg using a mask.

Embedded C
unsigned int mask = [1];
reg = reg & [2];
Drag options to blanks, or click blank then click option'
A~(1 << 5)
B1 << 5
Cmask
D~mask
Attempts:
3 left
💡 Hint
Common Mistakes
Not inverting the mask before AND.
Using the mask directly without inversion.
Shifting bits in the wrong direction.
5fill in blank
hard

Fill all three blanks to clear the bit at position pos in reg using a mask variable.

Embedded C
unsigned int mask = [1];
unsigned int inv_mask = [2];
reg = reg [3] inv_mask;
Drag options to blanks, or click blank then click option'
A1 << pos
B~mask
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of AND to clear the bit.
Not inverting the mask before AND.
Shifting bits right instead of left.