human
Gray to Binary and Binary to Gray conversion | Helper function to xor two characters.
Helper function to flip the bit.
function to convert binary string to gray string.
MSB of gray code is same as binary code.
Compute remaining bits , next bit is computed by doing XOR of previous and current in Binary.
Concatenate XOR of previous bit with current bit.
function to convert gray code string to binary string.
MSB of binary code is same as gray code.
Compute remaining bits.
If current bit is 0 , concatenate previous bit.
Else , concatenate invert of previous bit.
Driver Code"
Solution in Python:
 ... Give me a code to gray to Binary and Binary to Gray conversion and the other steps required?
assistant
#Here is code to gray to Binary and Binary to Gray conversion and the other steps required.
 def xor_c ( a , b ) :
	return '0' if ( a == b ) else '1' ;
def flip ( c ) :
	return '1' if ( c == '0' ) else '0' ;
def binarytoGray ( binary ) :
	gray = " " ;
	gray += binary [ 0 ] ;
	for i in range ( 1 , len ( binary ) ) :
		gray += xor_c ( binary [ i - 1 ] , binary [ i ] ) ;
	return gray ;
def graytoBinary ( gray ) :
	binary = " " ;
	binary += gray [ 0 ] ;
	for i in range ( 1 , len ( gray ) ) :
		if ( gray [ i ] == '0' ) :
			binary += binary [ i - 1 ] ;
		else :
			binary += flip ( binary [ i - 1 ] ) ;
	return binary ;
binary = "01001" ;
print ( " Gray ▁ code ▁ of " , binary , " is " , binarytoGray ( binary ) ) ;
gray = "01101" ;
print ( " Binary ▁ code ▁ of " , gray , " is " , graytoBinary ( gray ) ) ;