在VCKBase看到一段代码:
int func(int x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}
这里的x&(x-1)很眼熟的样子~
想起来以前看过一段FFT的代码,里面使用if( x&(x-1) )来判断x是否是2的整数次幂。
的确是十分巧妙,可惜忘了作者是谁了~
int func(int x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}
这里的x&(x-1)很眼熟的样子~
想起来以前看过一段FFT的代码,里面使用if( x&(x-1) )来判断x是否是2的整数次幂。
的确是十分巧妙,可惜忘了作者是谁了~
浙公网安备 33010602011771号