def hamming_weight(x):
    """
    Per stackoverflow.com/questions/407587/python-set-bits-count-popcount
    It is succint and describes exactly what we are doing.
    """
    return bin(x).count('1')