Skip to content

Instantly share code, notes, and snippets.

@milesrout
Created April 21, 2017 04:09
Show Gist options
  • Save milesrout/b3512236f0e90011fa9b791315e6c6b6 to your computer and use it in GitHub Desktop.
Save milesrout/b3512236f0e90011fa9b791315e6c6b6 to your computer and use it in GitHub Desktop.
milesrout@mac:~ $ python3
Python 3.6.0 (default, Dec 24 2016, 08:01:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('DATA.txt', 'r')
>>> data = f.read()
>>> data
'01011001 01101111 01110101 00100000\n01101010 01110101 01110011 01110100\n00100000 01110111 01100001 01110011\n01110100 01100101 01100100 00100000\n01111001 01101111 01110101 01110010\n00100000 01110100 01101001 01101101\n01100101 00101110\n'
>>> data.split()
['01011001', '01101111', '01110101', '00100000', '01101010', '01110101', '01110011', '01110100', '00100000', '01110111', '01100001', '01110011', '01110100', '01100101', '01100100', '00100000', '01111001', '01101111', '01110101', '01110010', '00100000', '01110100', '01101001', '01101101', '01100101', '00101110']
>>> data = data.split()
>>> data
['01011001', '01101111', '01110101', '00100000', '01101010', '01110101', '01110011', '01110100', '00100000', '01110111', '01100001', '01110011', '01110100', '01100101', '01100100', '00100000', '01111001', '01101111', '01110101', '01110010', '00100000', '01110100', '01101001', '01101101', '01100101', '00101110']
>>> [int(x, 2) for x in data]
[89, 111, 117, 32, 106, 117, 115, 116, 32, 119, 97, 115, 116, 101, 100, 32, 121, 111, 117, 114, 32, 116, 105, 109, 101, 46]
>>> [chr(int(x, 2)) for x in data]
['Y', 'o', 'u', ' ', 'j', 'u', 's', 't', ' ', 'w', 'a', 's', 't', 'e', 'd', ' ', 'y', 'o', 'u', 'r', ' ', 't', 'i', 'm', 'e', '.']
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment