Challenge 2: Clearing a Single Flag Without Disturbing the Others — Possible Solution ==================================================================== #include #define FLAG_READ (1 << 0) #define FLAG_WRITE (1 << 1) int main() { unsigned int flags = FLAG_READ | FLAG_WRITE; printf("before: %u\n", flags); flags &= ~FLAG_WRITE; printf("after: %u\n", flags); return 0; } Output: before: 3 after: 1 Explanation: ~FLAG_WRITE inverts every bit of FLAG_WRITE (0b10), producing a mask with every bit set to 1 EXCEPT bit 1 (the WRITE bit), which becomes 0. ANDing flags with that mask keeps every bit of flags unchanged except bit 1, which is forced to 0 regardless of its previous value -- exactly clearing FLAG_WRITE while leaving FLAG_READ (bit 0) completely untouched. before is 3 (0b11, both flags set); after is 1 (0b01, only FLAG_READ remains). WHY THIS WORKS AS AN ANSWER ------------------------------ This shows the numeric before/after values (3 then 1) confirming exactly one bit changed, and explains the AND-with-NOT'd-mask mechanism precisely -- inverting isolates the target bit as the only 0 in an otherwise all-1s mask, so ANDing can only ever clear that one bit and nothing else.