Tuesday, May 23, 2017

Round to next Power of 2

Calculate the next power of two higher than or equal to a given number
Usage:


for (i = [0: 100])
  echo(i, ":", next_pow2(i));

function next_pow2(x) = pow(2, ceil(log(x)/log(2))); 

No comments:

Post a Comment