C Program to count the number of ones in a 32 bit number.
#includeint bitcount(unsigned int n) { int count=0; while(n) { count+=n& 0x1u; n>>=1; } return count; } void main() { unsigned int g; int n; printf(" \n Enter the number : \n"); scanf("%u",&g); n=bitcount(g); printf("It has %d ones",n); }
No comments:
Post a Comment