def set_bit(current, epaddr, v):
    """
    >>> bin(set_bit(0, 0, 1))
    '0b1'
    >>> bin(set_bit(0, 2, 1))
    '0b100'
    >>> bin(set_bit(0b1000, 2, 1))
    '0b1100'
    >>> bin(set_bit(0b1100, 2, 0))
    '0b1000'
    >>> bin(set_bit(0b1101, 2, 0))
    '0b1001'
    """
    if v:
        return current | 1 << epaddr
    else:
        return current & ~(1 << epaddr)