Home » Unlabelled » Write a constant time consuming statement lot finding out If a given number Is a power of 2? | Embedded Systems
Saturday, 10 November 2012
Write a constant time consuming statement lot finding out If a given number Is a power of 2? | Embedded Systems
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”);
No comments:
Post a Comment