Write a Python Program to Convert Binary to Gray Code


Topic: Write a Python Program to Convert Binary to Gray Code

Solution

def binary_to_gray(n):
    """Convert Binary to Gray codeword and return it."""
    n = int(n, 2)
    n ^= (n >> 1)
    return bin(n)[2:]



List all Python Programs