Assuming MIN < x < MAX:
| trick | operation/effect | note |
|---|---|---|
x & (x - 1) |
clear lowest 1 bit | if result 0, then x is 2 |
| `x | (x + 1)` | set lowest 0 bit |
| `x | (x - 1)` | set all bits to right of lowest 1 bit |
x & (x + 1) |
clear all bits to right of lowest 0 bit | |
x & -x |
extract lowest 1 bit | |
~x & (x + 1) |
extract lowest 0 bit (as 1 bit) |