Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to mask the lower 4 bits of the variable value.
Embedded C
unsigned char masked = value [1] 0x0F;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) instead of AND (&) will not mask bits correctly.
Using XOR (^) changes bits instead of masking.
Using NOT (~) inverts bits, not mask.
✗ Incorrect
The AND operator (&) is used to mask bits. Using & 0x0F keeps only the lower 4 bits of
value.2fill in blank
mediumComplete the code to mask bits 4 to 7 (upper nibble) of value.
Embedded C
unsigned char masked = value [1] 0xF0;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) will set bits instead of masking.
Using shift operators (<<) alone does not mask bits.
Using XOR (^) flips bits, not mask.
✗ Incorrect
Using AND (&) with 0xF0 keeps bits 4 to 7 and clears bits 0 to 3.
3fill in blank
hardFix the error in the code to mask bits 2 and 3 of value.
Embedded C
unsigned char masked = value [1] 0x0C;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) sets bits instead of masking.
Using shift operators (<<, >>) do not mask bits directly.
✗ Incorrect
AND (&) with 0x0C (binary 00001100) keeps bits 2 and 3 only.
4fill in blank
hardFill both blanks to create a mask that keeps bits 1, 3, and 5 of value.
Embedded C
unsigned char mask = [1]; unsigned char masked = value [2] mask;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) instead of AND (&) to apply the mask.
Using wrong mask value that does not match bits 1, 3, and 5.
✗ Incorrect
0x2A in hex is binary 00101010, which has bits 1, 3, and 5 set. AND (&) with this mask keeps those bits.
5fill in blank
hardFill all three blanks to mask bits 0, 2, and 4 of value and store the result in masked.
Embedded C
unsigned char mask = [1]; unsigned char masked = value [2] mask [3] 0;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) instead of AND (&) to mask bits.
Using wrong mask value.
Adding a non-zero value changes the result.
✗ Incorrect
0x15 (binary 00010101) masks bits 0, 2, and 4. AND (&) applies the mask. Adding 0 does not change the result.