swappair a function swap odd and even bits in an integer with as few instructions as possible ex bit and bit 1 are swapped bit 2 and bit 3 are swapped for example 22 010110 41 101001 10 1010 5 0101 we can approach this as operating on the odds bit first and then the even bits we can mask all odd bits with 10101010 in binary aa then shift them right by 1 similarly we mask all even bit with 01010101 in binary 55 then shift them left by 1 finally we merge these two values by or operation odd bit arithmetic right shift 1 bit even bit left shift 1 bit we can approach this as operating on the odds bit first and then the even bits we can mask all odd bits with 10101010 in binary aa then shift them right by 1 similarly we mask all even bit with 01010101 in binary 55 then shift them left by 1 finally we merge these two values by or operation odd bit arithmetic right shift 1 bit even bit left shift 1 bit
def swap_pair(num):
    
    odd = (num & int('AAAAAAAA', 16)) >> 1
    
    even = (num & int('55555555', 16)) << 1
    return odd | even