unsigned n;
for(n=2; n<x; n*=2);
So I get:
x -> n
419 -> 512
560 -> 1024
87 -> 128
5 -> 8
1500 -> 2048
unsigned n;
for(n=2; n<x; n*=2);
So I get:
x -> n
419 -> 512
560 -> 1024
87 -> 128
5 -> 8
1500 -> 2048
unsigned long next_power_of_2(unsigned long x){ unsigned long n = 1; while(x >>= 1) n *= 2;}
unsigned long next_power_of_b(unsigned long x, unsigned long b){ return pow(b, log(x, b)); // where log(x, b) returns logb x}