Write a constant time consuming statement lot finding out If a given number Is a power of 2?

If n is the given number, then the expression (n & (n-1)) = 0 gives the logical output depicting if it is a power of 2 or not, if (n & (n-1) == 0) printf (“The given number is a power of 2”);

Be the first to comment

Leave a Reply

Your email address will not be published.


*