Write a Python function to convert Gray code to binary


Topic: Write a Python function to convert Gray code to binary

Solution

def gray_to_binary(n):
    n = int(n, 2) # convert to int
    mask = n
    while mask != 0:
        mask >>= 1
        n ^= mask
    return bin(n)[2:]
	
	
	



List all Python Programs