Complete the code to set the bit at position 3 in the number.
let num = 0b0000_1001; let result = num | (1 << [1]); println!("{:08b}", result);
Setting bit at position 3 means shifting 1 by 3 places and OR-ing it with the number.
Complete the code to clear the bit at position 2 in the number.
let num = 0b0000_1111; let result = num & !(1 << [1]); println!("{:08b}", result);
Clearing bit at position 2 requires shifting 1 by 2, negating it, and AND-ing with the number.
Fix the error in the code to toggle the bit at position 1.
let num = 0b0000_0101; let result = num [1] (1 << 1); println!("{:08b}", result);
Toggling a bit uses the XOR '^' operator with the mask.
Fill both blanks to set bit 4 and clear bit 0 in the number.
let num = 0b0001_0001; let result = (num [1] (1 << 4)) [2] !(1 << 0); println!("{:08b}", result);
Set bit 4 with OR '|', clear bit 0 with AND '&' and negated mask.
Fill all three blanks to toggle bit 3, set bit 1, and clear bit 0 in the number.
let num = 0b0000_1110; let result = ((num [1] (1 << 3)) [2] (1 << 1)) [3] !(1 << 0); println!("{:08b}", result);
Toggle bit 3 with XOR '^', set bit 1 with OR '|', clear bit 0 with AND '&' and negated mask.
