Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

isPowerOfTwo

  bool isPowerOfTwo(int x)
    {
        // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }
Source by www.hackerearth.com #
 
PREVIOUS NEXT
Tagged: #isPowerOfTwo
ADD COMMENT
Topic
Name
5+2 =