Created
January 1, 2017 11:12
-
-
Save ndubey/8361c146a7ef02a3ca37de85aea0d344 to your computer and use it in GitHub Desktop.
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
# count number of bits set in binary representation doesn't work on negative numbers | |
print("Enter a positive integer in decimal form:") | |
num = int(input()) | |
cnt = 0 | |
while num != 0: | |
cnt += num&1 | |
num = num>>1 | |
print(num) | |
print("Number of bits set: %d" %cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment