number of 1 binary number code example
Example 1: find no of 1's in a binary number
len(''.join(str(bin(122011)).split('0')))-1
Example 2: how to find the left most bit 1 in binary of any number
//C++ Code to find the value of 2^n = highestOneBit().
int highestOneBit(int i) {
i |= (i >> 1);
i |= (i >> 2);
i |= (i >> 4);
i |= (i >> 8);
i |= (i >> 16);
return i - (i >> 1);
}