标签:style blog color os strong 2014 re c
如果一个整数是2的整数次方,那么二进制表示中只有一位是1。将这个数减去1之后再与本身,结果为0则表示这个整数位2的整数次方。
bool func(int n)
{
return ((n-1)&n)==0;
}int func(int m,int n)
{
int temp = m^n;
int count = 0;
while(temp)
{
count++;
temp = (temp-1)&temp;
}
return count;
}标签:style blog color os strong 2014 re c
原文地址:http://blog.csdn.net/chdjj/article/details/38087273