Hi, i found the following way to do the required job fast, but am unable to understand how it works . Could someone please explain it.
nearest_pow (uint32_t num)
{
uint32_t n = num > 0 ? num - 1 : 0;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}
Thanks.