Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to invert all bits of the variable num using the NOT operator.
Embedded C
unsigned int num = 0x0F; unsigned int inverted = [1] num;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ! instead of ~ flips the logic but not the bits.
Using & or | does not invert bits.
✗ Incorrect
The bitwise NOT operator in C is
~. It flips every bit of the number.2fill in blank
mediumComplete the code to invert bits of value and store the result in result.
Embedded C
unsigned char value = 0xAA; unsigned char result = [1]value;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using & or | operators instead of ~.
Using ^ without a mask does not invert all bits.
✗ Incorrect
The
~ operator inverts all bits of the operand.3fill in blank
hardFix the error in the code to correctly invert bits of data.
Embedded C
unsigned int data = 0x1234; unsigned int inverted = [1]data;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ! instead of ~ causes incorrect results.
Confusing logical and bitwise operators.
✗ Incorrect
The logical NOT operator
! returns 0 or 1, not bitwise inversion. Use ~ for bitwise NOT.4fill in blank
hardFill both blanks to create a mask and invert only the lower 4 bits of num.
Embedded C
unsigned int num = 0x3C; unsigned int mask = [1]; unsigned int result = num [2] mask;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect mask values.
Using ~ which inverts all bits.
Using & or | which do not flip bits.
✗ Incorrect
Create a mask
0x0F with 1s in the lower 4 bits. XOR (^) the number with this mask inverts exactly those bits (XOR with 1 flips a bit, XOR with 0 leaves it unchanged).5fill in blank
hardFill the blanks to invert bits of value only where mask has 1s, leaving other bits unchanged.
Embedded C
unsigned int value = 0x55AA; unsigned int mask = [1]; unsigned int result = value [2] mask; // result now has bits inverted only where mask bits are 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of XOR.
Using ~ which inverts all bits unconditionally.
Using & which masks but does not flip.
✗ Incorrect
Use mask
0x00FF to target the lower 8 bits. XOR (^) flips bits where mask is 1.