/*
*********************************************
写一个函数返回参数值为1的个数
比如:15 0000 1111 4个1
*********************************************
*/
#include<stdio.h>
int count_one_bits(unsigned int value)
{
int a=value; //the int number that user input
int i=0; //count the number of '1'
while(a)
{
if(a%2 ==1)
{
i++;
}
a=a/2;
}
return i;
}
int main()
{
printf("the number of 1 is %d:\n",count_one_bits(12));
return 0;
}