一个小函数,输入一个无符号整数value,返回一个最接近的整数,它为2的n次幂,该整数>=value
Code
static unsigned int firstPO2From(unsigned int n)
{
--n;
cout<<n<<endl;
printf("%x\n",n);
n |= n >> 16;
cout<<n<<endl;
n |= n >> 8;
cout<<n<<endl;
n |= n >> 4;
cout<<n<<endl;
n |= n >> 2;
cout<<n<<endl;
n |= n >> 1;
cout<<n<<endl;
++n;
cout<<n<<endl;
return n;
}