How to Check if a Number is a Power of Two

How to check if a number is a power of two.  Give an integer, write a function to check if it is a power of two.

Example –

Input – 16   – 16 is a power of 2 (2^4).

Input – 15 – 15 is not a power of 2.

Input – 32- 32 is a power of 2 (2^5).

We can use multiple approaches to check whether a number is a power of 2 or not.