“`” 1、判断一个数是不是二的倍数,即判断该数二进制末位是不是0:

a % 2 == 0 或者a & 0x0001 == 0。

2、求一个数中1的位数,可以直接逐位除十取余判断:

   int fun(long x){   int _count = 0;while(x){   if(x % 10== 1)++_count;x /= 10;}   return _count;   }   int main(){   cout << fun(123321) << endl;return 0;   }`
            "```

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.