Baseline Bit Manipulation · Learn Bit Manipulation O(1) · O(1)
A telecom planner can only deploy tower clusters whose channel counts are exact powers of two, because the switching fabric splits and merges channels in halves. A cluster size qualifies precisely when its binary form carries a single 1 bit. Subtracting one from such a number flips that lone bit and all lower bits, so one AND against the original exposes any impostor.
Input: An integer n.
Output: true when n is a positive power of two, false otherwise.
-2^31 <= n <= 2^31 - 1Input: {"n":1}
Output: true
2^0 = 1 carries a single set bit.
Input: {"n":16}
Output: true
16 is 10000 — one bit, four zeros, a clean 2^4.