Is there a one line expression (possibly boolean) to get the nearest 2^n number for a given integer?
2^n
Example: 5,6,7 must be 8.
Round up to the next higher power of two: see bit-twiddling hacks.
In C:
unsigned int v; // compute the next highest power of 2 of 32-bit v v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++;
1.4m articles
1.4m replys
5 comments
57.0k users