Last active
July 27, 2016 04:58
-
-
Save plucury/6865288d4b5f13dfddcb73676ea2fc50 to your computer and use it in GitHub Desktop.
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
marks = {'a': '0', 'b': '1'} | |
def transfer(code): | |
i = 0 | |
binary = '' | |
while i < len(code): | |
cnt = '' | |
while code[i].isdigit(): | |
cnt += code[i] | |
i += 1 | |
binary += (int(cnt) if cnt else 1) * marks.get(code[i]) | |
i += 1 | |
bin_arr = [binary[i:i+8] for i in range(0, 32, 8)] | |
return '%s.%s.%s.%s' % tuple(map(lambda x: int(x, 2), bin_arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment