On Dec 16, 4:34 pm, "BartC" <b... at freeuk.com> wrote: > def p2(n): > p=1 > whileTrue: > if n<=p: return p > p<<=1 > return 0 > > for i in xrange(1000000): > x=p2(i) > > p2() calculates the smallest power of 2 >= it's operand. def p2(n): return 1 << n.bit_length()