human
Maximize a given unsigned number number by swapping bits at it 's extreme positions. | Python 3 program to find maximum number by swapping extreme bits ..
Traverse bits from both extremes.
Obtaining i - th and j - th bits.
Swapping the bits if lesser significant is greater than higher significant bit and accordingly modifying the number.
Driver code"
How can the above be solved in Python?
 ... Give me a code to maximize a given unsigned number number by swapping bits at it 's extreme positions?
assistant
#Here is code to maximize a given unsigned number number by swapping bits at it 's extreme positions.
 def findMax ( num ) :
	num_copy = num
	j = 4 * 8 - 1 ;
	i = 0
	while ( i < j ) :
		m = ( num_copy >> i ) & 1
		n = ( num_copy >> j ) & 1
		if ( m > n ) :
			x = ( 1 << i 1 << j )
			num = num ^ x
		i += 1
		j -= 1
	return num
if __name__ == " _ _ main _ _ " :
	num = 4
	print ( findMax ( num ) )