Complete the code to perform a bitwise AND operation between a and b.
int result = a [1] b;The bitwise AND operator & compares each bit of two integers and returns 1 only if both bits are 1.
Complete the code to set the 3rd bit of variable flags using bitwise OR.
flags = flags [1] (1 << 2);
The bitwise OR operator | sets a bit to 1 if either bit is 1. Shifting 1 by 2 sets the 3rd bit.
Fix the error in the code to clear the 2nd bit of variable status.
status = status [1] ~(1 << 1);
Bitwise AND with the negated mask clears the targeted bit. Using & with ~(1 << 1) clears the 2nd bit.
Fill both blanks to check if the 4th bit of num is set.
if ((num [1] (1 [2] 3)) != 0) { // bit is set }
Shift 1 left by 3 to target the 4th bit, then use bitwise AND to check if it is set.
Fill all three blanks to toggle the 5th bit of variable flags.
flags = flags [1] (1 [2] [3]);
Use XOR (^) with 1 shifted left by 4 to toggle the 5th bit.