Next Power of Two

Find the next power of two greater than or equal to a given number.

Code

General
import math
return 1 if n <= 1 else 2 ** math.ceil(math.log2(n))

Parameters

Number

Server

More Python Snippets