/************************************************************
Copyright (C), 1998-2006, Rx. Co., Ltd.
FileName: mainApp.cpp
Author: longronglin
Version : 1.0
Date: 2006-10-10
Description:
Function List:
1. int main()
History:
<author> <time> <version > <desc>
longronglin 2006/10/10 1.0 modify xxx .
***********************************************************/
#include <stdio.h>
/*
* 返回1为正确执行
* 主函数
*
*/
int func(int x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}
int main()
{
printf("%d",func(9999));
return (1);
}
答案是8。为9999转换为2进制1的个数。