方法一:
int n = 0;
int count = 0;
int i = 0;
scanf("%d", &n);
while (n)
{
n = n & n - 1;
count++;
}
方法二:
for (i = 0; i < 32; i++)
{
if (1 == ((n >> i) & 1))
count++;
}
方法一:
int n = 0;
int count = 0;
int i = 0;
scanf("%d", &n);
while (n)
{
n = n & n - 1;
count++;
}
方法二:
for (i = 0; i < 32; i++)
{
if (1 == ((n >> i) & 1))
count++;
}