-
-
Save pekkavaa/5cfbadecc7ed4e07b521afa4ce45be59 to your computer and use it in GitHub Desktop.
A terrible binary number printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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