0
0
Cprogramming~5 mins

Bitwise AND, OR, XOR in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A0
B1
CDepends on the other bits
DError
Which operator returns 1 only when bits are different?
AAND (&)
BNOT (~)
COR (|)
DXOR (^)
What is the result of 6 & 3 in binary? (6 = 0110, 3 = 0011)
A0010 (2)
B0111 (7)
C0101 (5)
D0001 (1)
If a = 4 (0100) and b = 5 (0101), what is a ^ b?
A0100 (4)
B0001 (1)
C0101 (5)
D0000 (0)
Which bitwise operator would you use to check if a specific bit is set?
AXOR (^)
BOR (|)
CAND (&)
DNOT (~)
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.