Clear Bit
AND with the inverse of that mask, so only bit i is forced to 0.
Decision · step 2 of 3Bit Manipulation: Clear a bit that was 1
The mask 1 shl 5 is 32, a single 1 at bit 5. Bit 5 of 178 is currently 1. AND with the inverted mask forces that one bit to 0 and leaves the rest alone.
What you will see
The inverted mask has a single zero; AND clears that bit.
Cost
| Best | O(1) |
|---|---|
| Average | O(1) |
| Worst | O(1) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, run it on your own input, try operations in any order.
Screen readers: Each bit announces its position and value; each step announces the operation and the resulting number in binary and decimal.
Reduced motion: Bits flip with a crossfade; masks appear in place.
Before this
Taught by the same lesson
Bit Manipulation covers these too, in the same run.