Efficient way to count number of 1s in the binary representation of a number in O(1) if you have enough memory to play with. This is an interview question I found on an onli
Below will work as well.
nofone(int x) { a=0; while(x!=0) { x>>=1; if(x & 1) a++; } return a; }