0
0
Cprogramming~5 mins

Bitwise NOT in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AUndefined
B0
C-1
D1
Which operator flips every bit of its operand?
A~ (bitwise NOT)
B& (bitwise AND)
C| (bitwise OR)
D! (logical NOT)
If x = 12 (binary 00001100), what is ~x in binary (8-bit)?
A00001100
B00000011
C11111111
D11110011
What is the difference between ~x and !x in C?
A~x flips bits; !x returns 1 if x is zero, else 0
B~x returns 1 if x is zero, else 0; !x flips bits
CBoth flip bits
DBoth return logical negation
What happens to the sign bit when applying bitwise NOT to a signed integer?
AIt stays the same
BIt flips, possibly changing the sign
CIt becomes zero
DIt becomes one
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.