Skip to content

Instantly share code, notes, and snippets.

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__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment