Recall & Review
beginner
What does the bitwise NOT operator (~) do to a binary number?
It flips every bit in the binary number: 0 becomes 1, and 1 becomes 0.
Click to reveal answer
beginner
Given an 8-bit number 00001111, what is the result of applying ~ (bitwise NOT)?
The result is 11110000 in binary, which is 240 in decimal if unsigned.
Click to reveal answer
intermediate
Why does applying bitwise NOT to an integer in C sometimes produce a negative number?
Because integers are stored in two's complement form, flipping bits changes the sign bit, often resulting in a negative number.
Click to reveal answer
intermediate
How is the bitwise NOT operator different from the logical NOT operator (!) in C?
Bitwise NOT (~) flips each bit individually, while logical NOT (!) converts any non-zero value to 0 and zero to 1.
Click to reveal answer
beginner
Write a simple C code snippet that uses bitwise NOT on an integer and prints the result.
int x = 5;
int y = ~x;
printf("~%d = %d\n", x, y);
// Output: ~5 = -6
Click to reveal answer
What is the result of ~0 in a 32-bit signed integer in C?
✗ Incorrect
All bits of 0 are 0, so ~0 flips all bits to 1, which is -1 in two's complement.
Which operator flips every bit of its operand?
✗ Incorrect
The ~ operator flips every bit individually.
If x = 12 (binary 00001100), what is ~x in binary (8-bit)?
✗ Incorrect
Flipping each bit of 00001100 gives 11110011.
What is the difference between ~x and !x in C?
✗ Incorrect
~x is bitwise NOT; !x is logical NOT.
What happens to the sign bit when applying bitwise NOT to a signed integer?
✗ Incorrect
Bitwise NOT flips all bits including the sign bit, which can change the sign.
Explain how the bitwise NOT operator works on an integer in C and why the result might be negative.
Think about how numbers are stored in memory.
You got /4 concepts.
Describe the difference between bitwise NOT (~) and logical NOT (!) operators in C.
One works on bits, the other on truthiness.
You got /4 concepts.