def set_flag(bits, bit, value):
    """
    Sets the flag value.

    :param bits: The bits
    :type bits: int
    :param bit: The bit index
    :type bit: int
    :param value: The bit value
    :type value: bool

    :returns: The bits
    :rtype: int
    """
    mask = 1 << bit
    return bits | mask if value else bits & ~mask