是返回1 不是返回0
方法1:
int checker ( int n )
{
return (n & (- n))== n ?1:0;
}
方法2:
做个判断的,
如果为正数,直接可以
return !(n & n-1);
如果为负数,需要对参数取反再加一回到正数上判断 如
tempN = (~n)+1;
return !(tempN &(tempN - 1));
是返回1 不是返回0
方法1:
int checker ( int n )
{
return (n & (- n))== n ?1:0;
}
方法2:
做个判断的,
如果为正数,直接可以
return !(n & n-1);
如果为负数,需要对参数取反再加一回到正数上判断 如
tempN = (~n)+1;
return !(tempN &(tempN - 1));