Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)
#include<iostream.h> #include<conio.h> /*no. of 1's in no. of 1's steps*/ int count(unsigned long int n) { int count=0; while(n) { count++; n=n&n-1; } return count ; }