0
0
Embedded Cprogramming~10 mins

AND for masking 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 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'
A|
B^
C~
D&
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.
2fill in blank
medium

Complete 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'
A&
B<<
C^
D|
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.
3fill in blank
hard

Fix 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'
A|
B&
C<<
D>>
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) sets bits instead of masking.
Using shift operators (<<, >>) do not mask bits directly.
4fill in blank
hard

Fill 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'
A0x2A
B&
C|
D0x15
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.
5fill in blank
hard

Fill 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'
A0x15
B&
C+
D|
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.