Bird
0
0
DSA Cprogramming~10 mins

Set Clear Toggle a Specific Bit in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the 3rd bit of variable x.

DSA C
x = x | (1 << [1]);
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for the bit position.
Using bitwise AND instead of OR.
2fill in blank
medium

Complete the code to clear the 4th bit of variable y.

DSA C
y = y & ~(1 << [1]);
Drag options to blanks, or click blank then click option'
A4
B3
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 instead of 3 for the bit position.
Forgetting to invert the mask with ~.
3fill in blank
hard

Fix the error in toggling the 5th bit of variable z.

DSA C
z = z ^ (1 << [1]);
Drag options to blanks, or click blank then click option'
A3
B5
C4
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 instead of 4 for the bit position.
Using OR or AND instead of XOR for toggling.
4fill in blank
hard

Fill both blanks to set bit 1 and clear bit 3 of variable a.

DSA C
a = (a | (1 << [1])) & ~(1 << [2]);
Drag options to blanks, or click blank then click option'
A1
B2
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up bit positions for set and clear.
Not negating the mask when clearing.
5fill in blank
hard

Fill all three blanks to toggle bit 0, set bit 2, and clear bit 4 of variable b.

DSA C
b = (b ^ (1 << [1])) | (1 << [2]); b = b & ~(1 << [3]);
Drag options to blanks, or click blank then click option'
A0
B2
C4
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong bit positions for toggle, set, or clear.
Forgetting to negate the mask when clearing.