0
0
Cprogramming~10 mins

Bitwise AND, OR, XOR in C - Interactive Code Practice

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 perform a bitwise OR operation between x and y.

C
int combined = x [1] y;
Drag options to blanks, or click blank then click option'
A^
B|
C&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical OR (||) instead of bitwise OR.
Using bitwise AND (&) instead of OR.
3fill in blank
hard

Fix the error in the code to perform a bitwise XOR operation between m and n.

C
int diff = m [1] n;
Drag options to blanks, or click blank then click option'
A^
B&
C|
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical AND (&&) or OR (||) instead of bitwise XOR.
Using bitwise AND (&) or OR (|) instead of XOR.
4fill in blank
hard

Fill both blanks to create a mask that keeps only the lower 4 bits of value.

C
int mask = (1 [1] 4) [2] 1;
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 (<<).
Adding 1 instead of subtracting 1.
5fill in blank
hard

Fill all three blanks to toggle the 3rd bit of num using XOR.

C
int toggle = num [1] (1 [2] 2 [3] 0);
Drag options to blanks, or click blank then click option'
A&
B^
C<<
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND (&) instead of XOR (^).
Using addition (+) instead of OR (|).