Bird
0
0
DSA Cprogramming~10 mins

Bit Manipulation Basics AND OR XOR NOT Left Right Shift 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 perform bitwise AND on two integers a and b.

DSA C
int result = a [1] b;
Drag options to blanks, or click blank then click option'
A|
B&
C^
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using | (bitwise OR) instead of & (bitwise AND).
Using ^ (bitwise XOR) which returns 1 only if bits differ.
2fill in blank
medium

Complete the code to perform a left shift by 2 bits on integer x.

DSA C
int shifted = x [1] 2;
Drag options to blanks, or click blank then click option'
A<<
B>>
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using >> (right shift) instead of << (left shift).
Using bitwise AND or OR operators mistakenly.
3fill in blank
hard

Fix the error in the code to perform bitwise NOT on variable val.

DSA C
int result = [1]val;
Drag options to blanks, or click blank then click option'
A~
B|
C&
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using & or | which are AND and OR operators.
Using ^ which is XOR, not NOT.
4fill in blank
hard

Fill both blanks to create a mask that sets the 3rd bit of number num using bitwise OR.

DSA C
int mask = 1 [1] 2;
int result = num [2] mask;
Drag options to blanks, or click blank then click option'
A<<
B>>
C|
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using right shift instead of left shift for mask.
Using AND instead of OR to set the bit.
5fill in blank
hard

Fill all three blanks to create a mask for the 1st bit, toggle the 1st bit of variable val using XOR, and isolate the 1st bit using AND.

DSA C
int mask = 1 [1] 0;
int toggled = val [2] mask;
int isolated = val [3] mask;
Drag options to blanks, or click blank then click option'
A<<
B^
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of XOR to toggle bits.
Using right shift instead of left shift for mask.