def pop_cnt(val, _type):
cnt = int()
power = int()
if _type == 'uint32':
bits = np.uint32(val)
while power < 32:
if val & 2**power != 0:
cnt += 1
power += 1
elif _type == 'uint64':
bits = bin(np.uint64(val))
while power < 64:
if val & 2**power != 0:
cnt += 1
power += 1
else:
raise Exception(Colors.red + "unsupported type passed to pop_cnt." + Colors.ENDC)
return cnt
评论列表
文章目录