Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to apply the bitwise NOT operator to the variable num.
C
int num = 5; int result = [1]num; printf("%d\n", result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise AND (&) instead of NOT (~).
Using bitwise OR (|) or XOR (^) operators.
✗ Incorrect
The bitwise NOT operator in C is the tilde symbol
~. It flips all bits of the number.2fill in blank
mediumComplete the code to print the bitwise NOT of the variable value.
C
int value = 0; int inverted = [1]value; printf("%d\n", inverted);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT (!) instead of bitwise NOT (~).
Using bitwise AND (&) or OR (|) by mistake.
✗ Incorrect
The bitwise NOT operator is
~, which flips all bits of the integer.3fill in blank
hardFix the error in the code to correctly compute the bitwise NOT of x.
C
int x = 12; int y = [1] x; printf("%d\n", y);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT (!) instead of bitwise NOT (~).
Using bitwise AND (&) or OR (|) operators.
✗ Incorrect
The bitwise NOT operator is
~. Using ! is logical NOT, which is incorrect here.4fill in blank
hardFill both blanks to create a dictionary-like structure using a struct and apply bitwise NOT to val.
C
struct Data {
int val;
};
struct Data d = {10};
int inverted = [1]d.[2];
printf("%d\n", inverted); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT (!) instead of bitwise NOT (~).
Using incorrect member name like
value.✗ Incorrect
Use the tilde (~) for bitwise NOT and access the member
val of the struct.5fill in blank
hardFill all three blanks to create a function that returns the bitwise NOT of its integer parameter.
C
int bitwiseNot(int [1]) { return [2][3]; } int main() { int num = 7; printf("%d\n", bitwiseNot(num)); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in parameter and return.
Using logical NOT (!) instead of bitwise NOT (~).
✗ Incorrect
The function parameter is
x. The return statement applies bitwise NOT (~) to x.