Skip to content

Instantly share code, notes, and snippets.

@plucury
Last active July 27, 2016 04:58
Show Gist options
  • Save plucury/6865288d4b5f13dfddcb73676ea2fc50 to your computer and use it in GitHub Desktop.
Save plucury/6865288d4b5f13dfddcb73676ea2fc50 to your computer and use it in GitHub Desktop.
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