def set_bit(bitmask, bit, is_on):
    """Set the value of a bit in a bitmask on or off.

    Uses the low bit is 1 and the high bit is 8.
    """
    bitshift = bit - 1
    if is_on:
        return bitmask | (1 << bitshift)
    return bitmask & (0xff & ~(1 << bitshift))
Set the value of a bit in a bitmask on or off.

    Uses the low bit is 1 and the high bit is 8.