0
0
Embedded Cprogramming~10 mins

NOT for inverting 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 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'
A|
B!
C&
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using ! instead of ~ flips the logic but not the bits.
Using & or | does not invert bits.
2fill in blank
medium

Complete 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'
A^
B~
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using & or | operators instead of ~.
Using ^ without a mask does not invert all bits.
3fill in blank
hard

Fix 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'
A~
B!
C^
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using ! instead of ~ causes incorrect results.
Confusing logical and bitwise operators.
4fill in blank
hard

Fill 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'
A0x0F
B~
C&
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect mask values.
Using ~ which inverts all bits.
Using & or | which do not flip bits.
5fill in blank
hard

Fill 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'
A0x00FF
B^
C~
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of XOR.
Using ~ which inverts all bits unconditionally.
Using & which masks but does not flip.