0

I need something like that:

st = "1001000"
bt = toByte(st)
print(bt) # b'H'

Thanks for your help.

1 Answer 1

1

You are looking for:

def tochr(bitstr):
    return chr(int(bitstr, 2))

or for a bytestring:

def tobyte(st):
    return bytes([int('1001000',2)])

For example:

>>> tochr('1001000')
'H'
>>> tobyte('1001000')
b'H'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.