Use inbuilt function
count += countSetBit ( i ) ; NEW_LINE return count ; NEW_LINE def countSetBit ( n ) : NEW_LINE count = 0 NEW_LINE while ( n ) : NEW_LINE count += n & 1 NEW_LINE n >>= 1 NEW_LINE return count NEW_LINE