RoundUpToPowerOf2

C++ code posted by aztack
created at 03 Jan 09:13

Edit | Back
1
2
3
4
5
6
7
8
9
10
unsigned int RoundUpToPowerOf2(unsigned int x){
  ASSERT(x<=0x80000000u);
  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;
}
206 Bytes in 2 ms with coderay