Program - function to Convert Binary to Gray Code


Topic: Program - function to Convert Binary to Gray Code

Solution

def binary_to_gray(n):
    n = int(n, 2) 
    n ^= (n >> 1)
    return bin(n)[2:]



List all Python Programs