Created
December 7, 2010 00:47
-
-
Save SamirTalwar/731282 to your computer and use it in GitHub Desktop.
Binary Solo
This file contains hidden or 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/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