Skip to content

Instantly share code, notes, and snippets.

@seece
Created June 3, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seece/5cfbadecc7ed4e07b521afa4ce45be59 to your computer and use it in GitHub Desktop.
Save seece/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