Power of 2

Find if Given number is power of 2 or not.
More specifically, find if given number can be expressed as 2^k where k >= 1.

Input:

number length can be more than 64, which mean number can be greater than 2 ^ 64 (out of long long range)

Output:

return 1 if the number is a power of 2 else return 0

Example:

Input : 128
Output : 1
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Power of 2 on Interview Code Editor
Sign Up
to access hints and editorial solutions for Power of 2
5116 successful submissions.
Asked In:
  • Amazon
Click here to start solving coding interview questions