计算一个整数二进制位中1的个数

来源:互联网 发布:win7下nginx配置php 编辑:程序博客网 时间:2024/05/18 01:49
int Get_count(int n)//方法一{    int count=0;    while (n)    {        ++count;        n=n&(n-1);    }}int Get_count(int n)//方法二{    int count=0;    unsigned int flag=0;    while (flag)    {        if (n&flag)        {            count++;        }        n=n<<1;    }}
阅读全文
0 0
原创粉丝点击