http://stackoverflow.com/questions/8637142/what-does-this-bit-manipulating-function-do
unsigned long ccNextPOT(unsigned long x){
x = x - 1;
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >>16);
return x + 1;
}
|
|
asked Dec 26 '11 at 15:45
|
|
|
|
|
The OR and SHIFT statements fills with ones all bits of x to the right of most significant bit (up to 32 bits). Together with the pre-decrement and post-increment statements, this computes (as the function name suggets) the next power-of-two number, equal or greater than the given number (if x is greater than 0 and less than 2^32)
|
answered Dec 26 '11 at 16:54
|
|
|
|
|
This function rounds x up to the next highest power of 2. It's exactly the code in here
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++;
|
|
answered Jul 31 '13 at 13:45
|
|
|
|