These problems ask about the shape of a bit pattern: where the ones sit, how far apart they are, whether they alternate, what survives when you fold a whole range together. Counting is not enough here - position matters.
Two identities do most of the work. n & (n - 1) clears the lowest set bit, so it is zero exactly when at most one bit was set. n & -n isolates that lowest set bit, so it tells you where the pattern starts. See Core Techniques for both.
A power of two has exactly one set bit, so n > 0 and n & (n - 1) == 0 settles it in one step - no loop, no logarithm. A power of four adds a position constraint on top: the single bit must land on an even index, which a constant mask like 0x55555555 checks directly.
Now the question is about spacing and runs. Alternating bits means n ^ (n >> 1) is all ones. A binary gap means the distance between consecutive set bits. Consecutive set bits mean n & (n >> 1) is non-zero. Each of these turns a "scan the string" description into one shift-and-mask expression.
Folding an operator over every value in [left, right] looks like an O(n) loop but is not. AND across a range keeps only the common binary prefix of the endpoints, because somewhere in the range every lower bit flips to zero. OR across a set behaves the opposite way: it saturates fast, so the first value it cannot produce is small.