human
Number formed by flipping all bits to the left of rightmost set bit | Function to get the total count.
Moving until we get the rightmost set bit.
To get total number of bits in a number.
Function to find the integer formed after flipping all bits to the left of the rightmost set bit.
Find the total count of bits and the rightmost set bit.
XOR given number with the number which has is made up of only totbits set.
To avoid flipping the bits to the right of the set bit , take XOR with the number made up of only set firstbits.
Driver Code"
Solution in Python:
 ... Write me a code to number formed by flipping all bits to the left of rightmost set bit and the other steps required?
assistant
#Here is code to number formed by flipping all bits to the left of rightmost set bit and the other steps required.
 def getTotCount ( num ) :
	totCount = 1
	firstCount = 1
	temp = 1
	while ( not ( num & temp ) ) :
		temp = temp << 1
		totCount += 1
	firstCount = totCount
	temp = num >> totCount
	while ( temp ) :
		totCount += 1
		temp = temp >> 1
	return totCount , firstCount
def flipBitsFromRightMostSetBit ( num ) :
	totbit , firstbit = getTotCount ( num )
	num1 = num ^ ( ( 1 << totbit ) - 1 )
	num1 = num1 ^ ( ( 1 << firstbit ) - 1 )
	return num1
if __name__ == ' _ _ main _ _ ' :
	n = 120
	print ( flipBitsFromRightMostSetBit ( n ) )