0
0
Embedded Cprogramming~10 mins

Why bitwise operations are essential in embedded in Embedded C - Test Your Understanding

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

Complete the code to set 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 & will clear bits instead of setting them.
Using >> is a shift operator, not for setting bits.
2fill in blank
medium

Complete the code to clear the 1st bit of the variable 'flags'.

Embedded C
flags = flags [1] ~(1 << 0);
Drag options to blanks, or click blank then click option'
A|
B^
C<<
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using | will set bits instead of clearing.
Using ^ toggles bits, not guaranteed to clear.
3fill in blank
hard

Fix the error in the code to toggle the 2nd bit of 'flags'.

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

Fill both blanks to check if the 4th bit of 'flags' is set.

Embedded C
if ((flags [1] (1 << 3)) [2] 0) {
    // bit 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 & will not isolate the bit.
Using == 0 checks if bit is clear, not set.
5fill in blank
hard

Fill all three blanks to create a mask for bits 0 to 3 and clear them in 'flags'.

Embedded C
mask = (1 [1] 4) - 1;
flags = flags [2] [3]mask;
// bits 0-3 cleared
Drag options to blanks, or click blank then click option'
A<<
B&
C~
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of & will set bits instead of clearing.
Not negating mask will clear wrong bits.