AlgoScope

Toggle Bit

XOR with the mask flips bit i and nothing else.

Bit manipulation, algorithm, beginner
Bit 0 is 0. The mask is 1.0011020314150617bit
Bit 0 is 0. The mask is 1.0011020314150617bit

Bit Manipulation: Flip a bit

Decision, step 2 of 3

The mask 1 shl 0 is 1, a single 1 at bit 0. Bit 0 of 178 is currently 0. XOR with the mask flips that one bit 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.