Skip to content

Instantly share code, notes, and snippets.

@jordanmack
Created February 14, 2020 19:10
Show Gist options
  • Save jordanmack/08a2dc513ca00abc779b7812c73f9bfd to your computer and use it in GitHub Desktop.
Save jordanmack/08a2dc513ca00abc779b7812c73f9bfd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
def format_binary(i):
s = bin(i)
s = s.replace("0b", "")
return s
def gray_code(n):
return n ^ (n >> 1)
def print_binary_gray_code(i):
b = format_binary(i)
g = format_binary(gray_code(i))
print(f"""{b} {g}""")
if __name__ == "__main__":
print_binary_gray_code(187836561118445077)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment