Get Bit
Shift right by i and keep the last bit.
Decision · step 2 of 3Bit Manipulation: Read one bit
The mask 1 shl 4 is 16, a single 1 at bit 4. Bit 4 of 178 is currently 1. Shift 178 right by 4 and keep the last bit.
What you will see
The bit at position i is isolated; everything else is masked away.
Cost
| Best | O(1) |
|---|---|
| Average | O(1) |
| Worst | O(1) |
| Space | O(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.
Leads to
Topics that need this one first.
Taught by the same lesson
Bit Manipulation covers these too, in the same run.