human
Closest ( or Next ) smaller and greater numbers with same number of set bits | Main Function to find next smallest number bigger than n.
Compute c0 and c1.
If there is no bigger number with the same no . of 1 's.
Driver Code.
input 1.
input 2"
How can the above be solved in Python?

What is a code to closest ( or Next ) smaller and greater numbers with same number of set bits and the other steps required?
assistant
#Here is code to closest ( or Next ) smaller and greater numbers with same number of set bits and the other steps required.
 def getNext ( n ) :
	c = n
	c0 = 0
	c1 = 0
	while ( ( ( c & 1 ) == 0 ) and ( c != 0 ) ) :
		c0 = c0 + 1
		c >>= 1
	while ( ( c & 1 ) == 1 ) :
		c1 = c1 + 1
		c >>= 1
	if ( c0 + c1 == 31 or c0 + c1 == 0 ) :
		return - 1
	return n + ( 1 << c0 ) + ( 1 << ( c1 - 1 ) ) - 1
if __name__ == ' _ _ main _ _ ' :
	n = 5
	print ( getNext ( n ) )
	n = 8
	print ( getNext ( n ) )