Complete the code to check if the 3rd bit (bit 2) of variable 'flags' is set.
if (flags & [1]) { // bit is set }
To check the 3rd bit (bit 2), we use 1 shifted left by 2 positions: 1 << 2.
Complete the code to check if the 5th bit (bit 4) of 'status' is set.
if ((status & [1]) != 0) { // bit is set }
1 << 5 which checks the 6th bit.The 5th bit is bit 4 (counting from 0), so use 1 << 4.
Fix the error in the code to correctly check if bit 1 of 'reg' is set.
if (reg & [1]) { // bit is set }
1 << 2 which checks bit 2 instead of bit 1.1 << 0 which checks bit 0.Bit 1 means shifting 1 by 1: 1 << 1.
Fill both blanks to complete the for loop that maps each bit position to whether it is set in 'value'.
for (int [1] = 0; [1] < 8; [1]++) { bits[[1]] = (value & (1 << [2])) != 0; }
Use the same loop variable i for both the loop and the bit shift.
Fill all three blanks to create a function that returns 1 if the bit at 'pos' in 'num' is set, else 0.
int is_bit_set(unsigned int num, int [1]) { return (num & (1 << [2])) [3] 0 ? 1 : 0; }
The function uses pos as parameter and bit position, and checks if the bit is not zero.
