TOTAL_BITS = 32 LOG2DICT = { 0: TOTAL_BITS} | { 1<<i: i for i in range(TOTAL_BITS) } def CountTrailingZeros(n): return LOG2DICT[n & -n]