0

So i have a function that converts an alphabet character to it's binary.

def toBinary(char):
    return "".join([format(ord(char), '#010b')[2:]])

For example, toBinary('a') gives me

01100001

How do i convert 01100001 back to the ascii 'a'?

Maxxx
  • 3,688
  • 6
  • 28
  • 55

2 Answers2

1

One way could be

c = chr(int(s, 2))

where s is the binary string.

Sufian Latif
  • 13,086
  • 3
  • 33
  • 70
1

Try This:

chr(int('01100001',2))
Rohit-Pandey
  • 2,039
  • 17
  • 24