counts = bytes(bin(x).count("1") for x in range(256)) # py2: use bytearray
a = 100 a.bit_length() # 7