Bitset
An 8-bit word as an array of bits: get, set, clear and toggle are one mask operation each.
Decision · step 2 of 3Bit Manipulation: Set a bit that was 0
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.
What you will see
A row of 0/1 digits; operations flip individual digits or whole words.
Cost
| test | O(1) |
|---|---|
| set | O(1) |
| and or xor | O(n / w) |
| Space | O(n / w) |
w is the machine word size.
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.
Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.
Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.
Related
Taught by the same lesson
Bit Manipulation covers these too, in the same run.