def bitceil(N):
 if hasattr(int, 'bit_length'):
  return (1 << int((N - 1)).bit_length())
 else:
  N = (int(N) - 1)
  for i in [1, 2, 4, 8, 16, 32]:
   N |= (N >> i)
  return (N + 1)

def bitceil ( N ) : if hasattr ( int , 'bit_length' ) : return ( 1 << int ( ( N - 1 ) ) . bit_length ( ) ) else : N = ( int ( N ) - 1 ) for i in [ 1 , 2 , 4 , 8 , 16 , 32 ] : N |= ( N >> i ) return ( N + 1 )
find the bit immediately greater than or equal to n note: this works for numbers up to 2 ** 64 .