2进制里1的个数

fun返回:        x用2进制表示,里面包含1的个数。

int fun(int x)
{
	int ans=0;
	while(x)
	{
		ans++;
		x&=(x-1);
	}
	return ans;
}


你可能感兴趣的:(杂类)