AlgoScope

Bitset

An 8-bit word as an array of bits: get, set, clear and toggle are one mask operation each.

Data structures, data structure, intermediate
Set bit 2 of 178, which is 10110010 in binary.0011020314150617
Set bit 2 of 178, which is 10110010 in binary.0011020314150617

Bit Manipulation: Set a bit that was 0

Start, step 1 of 3

Set bit 2 of 178. 178 is 10110010 in binary. Bit 0 is on the left here, so each index is its bit number.

How bit manipulation works

Cost

Test
O(1)
Set
O(1)
And or xor
O(n / w)
Space
O(n / w)

w is the machine word size.

Leads to

Topics that need this one first.

Taught by the same lesson

Bit Manipulation covers these too, in the same run.