AlgoScope

Bitmask

TechniqueintermediateBit Manipulation

Use the bits of an integer as a set of booleans.

Decision · step 4 of 9Bitmask: A set in one integer
100201302403

has 2: mask and (1 shl 2) is not zero, so element 2 is in.

Open in the player →or start at step 4

What you will see

Each bit position is labelled with the element it represents; set membership is a lit bit.

How bitmask works →

Cost

SpaceO(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

Leads to

Topics that need this one first.

Taught by the same lesson

Bitmask covers these too, in the same run.