def next_power_of_2(n):
 n -= 1
 shift = 1
 while ((n + 1) & n):
  n |= (n >> shift)
  shift *= 2
 return max(4, (n + 1))

def next_power_of_2 ( n ) : n -= 1 shift = 1 while ( ( n + 1 ) & n ) : n |= ( n >> shift ) shift *= 2 return max ( 4 , ( n + 1 ) )
return next power of 2 greater than or equal to n .