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'?

0

2 Answers 2

1

One way could be

c = chr(int(s, 2))

where s is the binary string.

Sign up to request clarification or add additional context in comments.

2 Comments

what does the 2 represents?
The base in which you want to convert the number in. The default value is 10.
1

Try This:

chr(int('01100001',2))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.