Binary to Text Script

def changetobin(c):
    return [bin(ord(i)) for i in c]

def tostr(items):
    s = ''
    for item in items:
        item = item[2:]
        s = s+ chr(sum([(2**i)*int(item[(len(item))-i-1]) for i in range(0,len(item))]))
    return s

if __name__=="__main__":
    items = changetobin('python')
    print "output: "+ tostr(items)

Other articles with the same tag

  • Python datetime snippets
  • Alternate Small Caps Text Using Angular
  • Debugging Flask app with pdb
  • Brand icons using Font-Awesome
  • Python tidbits
  • Prime class to find nth prime
  • Factorials of big numbers
  • Back