Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Como contar o número do bits 1 para um inteiro (não negativo)
def count_bits(x):
qty_ones = 0
while x:
qty_ones += x & 1
x >>= 1
return qty_ones
if __name__ == "__main__":
print(count_bits(13))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.