def swap(number, i1, i2):
    """
    Swap given bits from number.

    :param number: A number
    :type number: int
    :param i1: Bit index
    :type i1: int
    :param i2: Bit index
    :type i2: int
    :return: A number with given bits swapped.
    :rtype: int

    >>> swap(0b101011, 1, 4) == 0b111001
    True

    """
    b1 = (1 << i1)
    b2 = (1 << i2)
    v1 = number & b1
    v2 = number & b2

    if v1 and v2 or not (v1 or v2):
        return number
    if v1:
        number ^= b1
        number |= b2
    else:
        number |= b1
        number ^= b2
    return number