Created
August 15, 2015 16:13
-
-
Save viveksyngh/f8e93c269602b940337f to your computer and use it in GitHub Desktop.
Find if Given number is power of 2 or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'Vivek' | |
| #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. | |
| def power(A): | |
| temp = int(A) | |
| A = int(A) | |
| Sum = 0 | |
| while A != 0 : | |
| Sum += A%2 | |
| A = A/2 | |
| if Sum == 1 and temp != 1 : | |
| return 1 | |
| else : | |
| return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment