一个数的二进制中有多少个1

int bit(unsigned int x)
{
    int c = 0;
    while( x )
    {
        c++;
        x = (x & (x - 1));
    }
    return c;
}

猜你喜欢

转载自blog.csdn.net/asdasdasdasasd1111/article/details/80950929