我现在所能想到的方法就是先按位右移,然后与1,并累加。

 

int src = 123;
int i = 0;
int count = 0;
while(i < 33)
{
    count 
+= (src >> ++i) & 1;
}

 

 

相关文章: