Skip to content

Instantly share code, notes, and snippets.

@m4hi2
Created October 4, 2022 04:30
bit counter example from EPI book
def count_bits(x):
num_bits = 0
while x:
num_bits += x & 1
x = x >> 1
return num_bits
for i in range(10):
print(count_bits(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment