human
How to swap two bits in a given integer ? | This function swaps bit at positions p1 and p2 in an integer n.
Move p1 'th to rightmost side.
Move p2 'th to rightmost side.
XOR the two bits.
Put the xor bit back to their original positions.
XOR ' x ' with the original number so that the two sets are swapped.
Driver program to test above function"
Solution in Python:
 ... Can you provide a code to how to swap two bits in a given integer?
assistant
#Here is code to how to swap two bits in a given integer .
 def swapBits ( n , p1 , p2 ) :
	bit1 = ( n >> p1 ) & 1
	bit2 = ( n >> p2 ) & 1
	x = ( bit1 ^ bit2 )
	x = ( x << p1 ) | ( x << p2 )
	result = n ^ x
	return result
if __name__ == ' _ _ main _ _ ' :
	res = swapBits ( 28 , 0 , 3 )
	print ( " Result ▁ = ▁ " , res )