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)

 ;)

Difficulty: introductory

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')

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

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

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

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