Using the bitwise & operator, only n’s that are powers of two will satisfy the relationship n & (n-1) = 0. This, however incorrectly returns 0 as a power of 2. n must be strictly positive for this to work. To fix this we use !(n & (n-1)) && n.