The __Hamming weight__ of a string is the number of symbols that are different from the zero-symbol of the alphabet used. There are several algorithms for efficient computing of the Hamming weight for numbers. In this Kata, speaking technically, you have to find out the number of '1' bits in a binary representation of a number. Thus,

The interesting part of this task is that you have to do it *without* string operation (hey, it's not really interesting otherwise)

 ;)

Source: codewars | Difficulty: EASY
Tags: Bit manipulation

Starter code: def hamming_weight(x):
	

Solutions:
def hamming_weight(x):
	return bin(x).count('1')


hamming_weight = lambda x: list(bin(x)).count('1')


def hamming_weight(x):
	count = 0
	while x:
		x &= x - 1
		count += 1
	return count


def hamming_weight(x):
	w = 0
	while x:
		w += x & 1
		x >>= 1
	return w


def hamming_weight(x):
	return '{:b}'.format(x).count('1')


hamming_weight = lambda x: str(bin(x)).count('1')