0
0
Cprogramming~10 mins

Bitwise NOT in 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 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'
A^
B&
C|
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise AND (&) instead of NOT (~).
Using bitwise OR (|) or XOR (^) operators.
2fill in blank
medium

Complete 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'
A&
B^
C~
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT (!) instead of bitwise NOT (~).
Using bitwise AND (&) or OR (|) by mistake.
3fill in blank
hard

Fix 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'
A~
B!
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT (!) instead of bitwise NOT (~).
Using bitwise AND (&) or OR (|) operators.
4fill in blank
hard

Fill 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'
A~
B!
Cval
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT (!) instead of bitwise NOT (~).
Using incorrect member name like value.
5fill in blank
hard

Fill 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'
Ax
B~
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in parameter and return.
Using logical NOT (!) instead of bitwise NOT (~).