Next Power of Two

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

Code

General
n <= 1 ? 1 : 2 ** Math.log2(n).ceil

Parameters

Number

Server

More Ruby Snippets