0
0
Embedded Cprogramming~10 mins

OR for setting bits 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 2 of the variable 'flags'.

Embedded C
flags [1] (1 << 2);
Drag options to blanks, or click blank then click option'
A|=
B&=
C=
D^=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&=' clears bits instead of setting them.
Using '^=' toggles bits instead of just setting them.
2fill in blank
medium

Complete the code to set bits 0 and 3 of 'status' using OR.

Embedded C
status [1] (1 << 0) | (1 << 3);
Drag options to blanks, or click blank then click option'
A&=
B=
C^=
D|=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' overwrites all bits, losing previous data.
Using '&=' clears bits instead of setting them.
3fill in blank
hard

Fix the error in the code to correctly set bit 5 of 'control'.

Embedded C
control [1] 1 << 5;
Drag options to blanks, or click blank then click option'
A=
B|=
C^=
D&=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' overwrites all bits, losing previous settings.
Using '&=' clears bits instead of setting them.
4fill in blank
hard

Fill both blanks to set bits 1 and 4 of 'reg' using OR.

Embedded C
reg [1] (1 << 1 [2] 1 << 4);
Drag options to blanks, or click blank then click option'
A|=
B&
C|
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of '|' to combine bits clears bits.
Using '^' toggles bits instead of setting them.
5fill in blank
hard

Fill all three blanks to set bits 0, 2, and 7 of 'flags' using OR.

Embedded C
flags [1] (1 [2] 1 << 2 [3] 1 << 7);
Drag options to blanks, or click blank then click option'
A|=
B&
C|
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' clears bits instead of setting them.
Using '^' toggles bits instead of setting them.