Showing posts with label 1 bits counter. Show all posts
Showing posts with label 1 bits counter. Show all posts
on Sunday, 14 April 2013

/* Count number of 1 bits */
#include<stdio.h>

int counter(int data){
int count=0;
int loop_counter=1;
int test=1;
while(loop_counter<=16){
if(data&test)
count++;
test=test<<1;
loop_counter++;
}

return count;
}


void main(){
int data=32768; // can take any data in input
printf(" No. of 1 bits = %d",counter(data));

}