AlgoScope

Clear Bit

AND with the inverse of that mask, so only bit i is forced to 0.

Bit manipulation, algorithm, beginner
Bit 5 is 1. The mask is 32.0011020314150617bit
Bit 5 is 1. The mask is 32.0011020314150617bit

Bit Manipulation: Clear a bit that was 1

Decision, step 2 of 3

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.

How bit manipulation works

Cost

Best
O(1)
Average
O(1)
Worst
O(1)
Space
O(1)

Before this

Taught by the same lesson

Bit Manipulation covers these too, in the same run.