human
Toggle all bits after most significant bit | Returns a number which has all set bits starting from MSB of n.
This makes sure two bits ( From MSB and including MSB ) are set.
This makes sure 4 bits ( From MSB and including MSB ) are set.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to toggle all bits after most significant bit and the other steps required.
 def setAllBitsAfterMSB ( n ) :
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return n
def toggle ( n ) :
	n = n ^ setAllBitsAfterMSB ( n )
	return n
n = 10
n = toggle ( n )
print ( n )