[ create a new paste ] login | about

Link: http://codepad.org/MOQkkc1Q    [ raw code | output | fork ]

ramachikkala - C, pasted on Feb 10:
int pop_count (unsigned);
int pop_count (unsigned bitstring){
int i;
int population_count = 0;

for(i=0;i<32;i++){
if (bitstring & 0x1){
population_count ++;
}
bitstring = bitstring >> 1;
}

return population_count;

}

int main () {

unsigned input = 0xf3f3;
unsigned result = 0;
result = pop_count(input);
printf("\n population count is %d", result);
return 1;
}


Output:
1
2

 population count is 12


Create a new paste based on this one


Comments: