Skip to content

Instantly share code, notes, and snippets.

@SamirTalwar
Created December 7, 2010 00:47
Show Gist options
  • Select an option

  • Save SamirTalwar/731282 to your computer and use it in GitHub Desktop.

Select an option

Save SamirTalwar/731282 to your computer and use it in GitHub Desktop.
Binary Solo
#!/usr/bin/env python
from os import system
from sys import argv
BITS = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01]
def asciiToBin(ascii, bitSep=' ', byteSep='. '):
return byteSep.join(bitSep.join('1' if bit & ord(char) else '0'
for bit in BITS)
for char in ascii)
if __name__ == "__main__":
if len(argv) == 2:
system("say " + asciiToBin(argv[1]))
elif len(argv) == 3 and argv[1] == '-p':
print asciiToBin(argv[2], '', ' ')
system("say " + asciiToBin(argv[2]))
else:
print "Usage: " + argv[0] + " <text>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment