0
0
Cprogramming~10 mins

Why bitwise operations are needed in C - Test Your Understanding

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

Complete the code to perform a bitwise AND operation between a and b.

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 logical AND (&&) instead of bitwise AND (&).
Using bitwise OR (|) instead of AND.
2fill in blank
medium

Complete the code to set the 3rd bit of variable flags using bitwise OR.

C
flags = flags [1] (1 << 2);
Drag options to blanks, or click blank then click option'
A|
B<<
C^
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise AND (&) which clears bits.
Using XOR (^) which toggles bits.
3fill in blank
hard

Fix the error in the code to clear the 2nd bit of variable status.

C
status = status [1] ~(1 << 1);
Drag options to blanks, or click blank then click option'
A|
B^
C&
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) which sets bits instead of clearing.
Using XOR (^) which toggles bits.
4fill in blank
hard

Fill both blanks to check if the 4th bit of num is set.

C
if ((num [1] (1 [2] 3)) != 0) {
    // bit is set
}
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 AND.
Shifting bits in the wrong direction.
5fill in blank
hard

Fill all three blanks to toggle the 5th bit of variable flags.

C
flags = flags [1] (1 [2] [3]);
Drag options to blanks, or click blank then click option'
A&
B^
C<<
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND (&) which clears bits.
Using OR (|) which sets bits.