Wednesday, October 8, 2014

How to Check if the Number is Some Power of 2?

To check if some number is a power of two there many methods available but there is an efficient one to do this. First of all assure that the number is not (because zero is not some power of two). Then assure if the (number - 1) and number's logical and is zero. Let's take a look what is happening behind this logical and operator. You may run it for any power of two.

1 comment :