Skip to content

Instantly share code, notes, and snippets.

@oalee
Created December 22, 2016 11:28
Show Gist options
  • Save oalee/9a3221c419eead45bf051a687caba4be to your computer and use it in GitHub Desktop.
Save oalee/9a3221c419eead45bf051a687caba4be to your computer and use it in GitHub Desktop.
decode binary string using a defined decode function and prints assci of decoded binary
#! /usr/bin/python
def decode(input):
if input == "0001":
return "00"
if input == "0010":
return "01"
if input == "0100":
return "10"
if input == "1000":
return "11"
return "Err"
def printArray(arr):
s = ""
for item in arr:
s += chr(int(item,2))
print s
input = "00100010 \
00011000 00100010 00101000 00100001 01000010 00100010 00100001 00100001 00011000 \
00100001 01000001"
print 'input is ' + input
decodeds = []
for item in input.split(" "):
decoded = decode(item[0:4]) + decode(item[4:])
decodeds += [decoded]
joint = []
for i in range(0, len(decodeds), 2):
a = decodeds[i] + decodeds[i+1]
joint += [a]
print 'decoded input is '
print joint
print 'using ascci table : '
printArray(joint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment