In this post will be discussing how to calculate if a number is a power of two or not. As an example, 8 is a power of two but the number 10 is not.
There are many ways we can solve this.
First, we will take an approach which is simple and iterative. In this case, we will calculate the power of two one by one and check with the supplied number. The below code illustrates it.
So, from the client code, the above code returns true for the number 8388608.