Skip to content

Instantly share code, notes, and snippets.

@pekkavaa
Created June 3, 2016 15:20
Show Gist options
  • Save pekkavaa/5cfbadecc7ed4e07b521afa4ce45be59 to your computer and use it in GitHub Desktop.
Save pekkavaa/5cfbadecc7ed4e07b521afa4ce45be59 to your computer and use it in GitHub Desktop.
A terrible binary number printer
#!/usr/bin/python
import sys
from ast import literal_eval
if len(sys.argv) != 2:
print "Usage: ebin INTEGER"
sys.exit(1)
s = "{0:08b}".format(literal_eval(sys.argv[1]))
n = 4 # split into 4 bit blocks
# awful reversing hack to get proper formatting
s = s[::-1]
parts = [s[i:i+n] for i in range(0, len(s), n)]
parts = [x[::-1] for x in parts]
print " ".join(parts[::-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment