Created
October 4, 2022 04:30
bit counter example from EPI book
This file contains 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
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