nextPowerOfTwo function Utility
- int v
Calculates the next power of two greater than or equal to the given integer v
.
v
must be a positive integer.
Implementation
int nextPowerOfTwo(int v) {
assert(v > 0, "nextPowerOfTwo: no negative value allowed");
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
return (++v);
}