AlgoScope

Set Bit

OR with a mask that has a single 1 at bit i.

Bit manipulation, algorithm, beginner
Bit 2 is 0. The mask is 4.0011020314150617bit
Bit 2 is 0. The mask is 4.0011020314150617bit

Bit Manipulation: Set a bit that was 0

Decision, step 2 of 3

The mask 1 shl 2 is 4, a single 1 at bit 2. Bit 2 of 178 is currently 0. OR with the mask forces that one bit to 1 and leaves the rest alone.

How bit manipulation works

Cost

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

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

Bit Manipulation covers these too, in the same run.