Bird
0
0
DSA Cprogramming~5 mins

Set Clear Toggle a Specific Bit in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean to set a specific bit in a number?
Setting a bit means changing that bit to 1, regardless of its current value.
Click to reveal answer
beginner
How do you clear a specific bit in a number?
Clearing a bit means changing that bit to 0, regardless of its current value.
Click to reveal answer
beginner
What does it mean to toggle a specific bit?
Toggling a bit means changing it from 0 to 1 or from 1 to 0, flipping its current value.
Click to reveal answer
intermediate
Which operator is used to set a bit at position pos in C?
The bitwise OR operator (|) with a mask: num | (1 << pos) sets the bit at pos.
Click to reveal answer
intermediate
How do you toggle a bit at position pos in C?
Use the bitwise XOR operator (^): num ^ (1 << pos) flips the bit at pos.
Click to reveal answer
Which operation sets the 3rd bit (0-based) of number num in C?
Anum ^ (1 << 3)
Bnum & ~(1 << 3)
Cnum | (1 << 3)
Dnum & (1 << 3)
How do you clear the 2nd bit of num?
Anum & ~(1 << 2)
Bnum | (1 << 2)
Cnum ^ (1 << 2)
Dnum & (1 << 2)
What does num ^ (1 << pos) do?
ASets the bit at pos
BToggles the bit at pos
CClears the bit at pos
DChecks the bit at pos
If num = 8 (1000 binary), what is num | (1 << 1)?
A10 (1010 binary)
B12 (1100 binary)
C0 (0000 binary)
D9 (1001 binary)
Which operator is used to clear a bit?
ABitwise OR (|)
BBitwise XOR (^)
CBitwise NOT (~)
DBitwise AND (&) with negated mask
Explain how to set, clear, and toggle a specific bit in a number using bitwise operators in C.
Think about how each operator affects bits: OR sets, AND clears, XOR flips.
You got /3 concepts.
    Describe a real-life example where toggling a bit might be useful.
    Imagine a light switch that can be flipped on or off.
    You got /3 concepts.