I wrote a program to convert binary code to Gray code using only string operation. I want to check the feasibility of my code and also whether it's the right or wrong approach.
def binary_to_gray(x):
x = str(x)
gray = x[0]
for i in range(len(x) - 1):
if (x[i] == x[i + 1]):
gray += "0"
else :
gray += "1"