0
0
Embedded Cprogramming~10 mins

XOR for toggling 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 toggle the 3rd bit of the variable flags.

Embedded C
flags = 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 & or | instead of ^ will not toggle bits correctly.
2fill in blank
medium

Complete the code to toggle the least significant bit of status.

Embedded C
status [1]= 1;
Drag options to blanks, or click blank then click option'
A^
B&
C|
D<<
Attempts:
3 left
💡 Hint
Common Mistakes
Using &= or |= will not toggle the bit.
3fill in blank
hard

Fix the error in toggling the 5th bit of control.

Embedded C
control = control [1] (1 << 4);
Drag options to blanks, or click blank then click option'
A^
B<<
C|
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using | sets the bit instead of toggling it.
4fill in blank
hard

Fill both blanks to toggle the 2nd bit and check if it was set before toggling.

Embedded C
if ((flags [1] (1 << 1)) != 0) {
    flags [2]= (1 << 1);
}
Drag options to blanks, or click blank then click option'
A&
B^
C|
D<<
Attempts:
3 left
💡 Hint
Common Mistakes
Using | to check bits is incorrect.
Using |= toggles incorrectly.
5fill in blank
hard

Fill all three blanks to toggle the 4th bit of reg only if it is currently set.

Embedded C
if (reg [1] (1 << 3)) {
    reg [2]= (1 << 3);
    result = reg [3] (1 << 3);
}
Drag options to blanks, or click blank then click option'
A&
B^
C|
D<<
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of & to check or read bits.
Using |= instead of ^= to toggle bits.