def set_bit(number, site, N, bit):
    """
    Change the bit value of number at a single site.

    :param number: the number to be changed
    :param site: the index of the site starting from left
    :param bit: the bit value to be changed
    :returns: the changed number
    """
    if bit:
        return number | (1 << (N-site))
    else:
        return number & ~(1 << (N-site))