#include <stdio.h>
#include <stdlib.h>
int ret_one_bit_num(unsigned int);
void main(){
int rlt = 0, input = 9;
rlt = ret_one_bit_num(input);
printf("%d have [%d] bit is 1\r\n", input
, rlt
); }
int ret_one_bit_num(unsigned int n)
{
int count = 0;
while(n!=0)
{
if(n & 1 == 1)
count++;
n>>=1;
}
return count;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KaW50IHJldF9vbmVfYml0X251bSh1bnNpZ25lZCBpbnQpOwp2b2lkIG1haW4oKXsKICAgIGludCBybHQgPSAwLCBpbnB1dCA9IDk7CgogICAgcmx0ID0gcmV0X29uZV9iaXRfbnVtKGlucHV0KTsKICAgIHByaW50ZigiJWQgaGF2ZSBbJWRdIGJpdCAgaXMgMVxyXG4iLCBpbnB1dCwgcmx0KTsKICAgIHN5c3RlbSgicGF1c2UiKTsKfQppbnQgcmV0X29uZV9iaXRfbnVtKHVuc2lnbmVkIGludCBuKQp7CiAgICBpbnQgY291bnQgPSAwOwogICAgd2hpbGUobiE9MCkKICAgIHsKICAgICAgICBpZihuICYgMSA9PSAxKQogICAgICAgICAgICBjb3VudCsrOwogICAgICAgIG4+Pj0xOwogICAgfSAgICAKICAgIHJldHVybiBjb3VudDsKfQ==