How can you tell if a number is a power of two?

That’s easy if it’s in the form 2^{n}, where n is an integer. For example, 2^{12}, 2^{0}, and 2^{-37} are powers of two. That is by definition. But what about arbitrary positive numbers like 16,392, 524,288, or 0.00390625? Are they powers of two? Here’s how to tell — if they can be simplified to the form 2^{n}, they are; if they can’t, they’re not.

Continue reading “How to Check If a Number Is a Power of Two”