Recall & Review
beginner
What does the bitwise AND operator (&) do in C?
It compares each bit of two numbers and returns 1 only if both bits are 1; otherwise, it returns 0.
Click to reveal answer
beginner
Explain the bitwise OR operator (|) in simple terms.
It compares each bit of two numbers and returns 1 if at least one of the bits is 1; otherwise, it returns 0.
Click to reveal answer
beginner
What is the result of the bitwise XOR operator (^) when both bits are the same?
The result is 0 because XOR returns 1 only when the bits are different.
Click to reveal answer
beginner
How would you describe bitwise operators using a real-life example?
Think of two light switches (bits). AND means both switches must be ON to get light. OR means if either switch is ON, the light is ON. XOR means the light is ON only if exactly one switch is ON.
Click to reveal answer
beginner
What is the output of this C code snippet?
int a = 5; // binary 0101
int b = 3; // binary 0011
int c = a & b;
The output value of c is 1 because 0101 & 0011 = 0001 in binary.
Click to reveal answer
What does the bitwise OR operator (|) return when both bits are 0?
✗ Incorrect
Bitwise OR returns 1 if at least one bit is 1; if both are 0, it returns 0.
Which operator returns 1 only when bits are different?
✗ Incorrect
XOR returns 1 only when the bits differ.
What is the result of 6 & 3 in binary?
(6 = 0110, 3 = 0011)
✗ Incorrect
Bitwise AND of 0110 & 0011 is 0010, which is 2.
If a = 4 (0100) and b = 5 (0101), what is a ^ b?
✗ Incorrect
XOR of 0100 and 0101 is 0001, which is 1.
Which bitwise operator would you use to check if a specific bit is set?
✗ Incorrect
AND is used to check if a specific bit is set by masking other bits.
Describe how bitwise AND, OR, and XOR operators work with examples.
Think about comparing bits one by one.
You got /4 concepts.
Explain a real-life analogy to understand bitwise AND, OR, and XOR.
Use everyday objects to explain bits.
You got /4 concepts.