def problem_5_6(n):
    """ Write a program to swap odd and even bits in an integer with as few
    instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit
    3 are swapped, etc).
    """
    def is_set_bit(x, i):
        return (x & (1 << i)) != 0

    def toggle_bit(x, i):
        return (x ^ (1 << i))

    def reverse(x, i):
        """ Reverses bit i with bit i+1 in number x. """
        i_is_set = is_set_bit(x, i)
        j_is_set = is_set_bit(x, i+1)
        if (not i_is_set and j_is_set) or (i_is_set and not j_is_set):
            x = toggle_bit(x, i)
            x = toggle_bit(x, i+1)
        return x

    num_bits = len(bin(n)) - 2
    for i in range(0, num_bits, 2):
        n = reverse(n, i)
    return n