tags:

views:

22

answers:

2

If you have a int and you wish to convert it to a single char string you can use the function chr()

Is there a way to convert an int to a single char binary stream?

e.g:

>>> something(97)
b'a'

What is the something?

A: 

You can do:

bytes(chr(97))
martin
and that won't fail if given any number 0-255?
Skyler
it won't fail, this one-liner runs fine: `for x in range(256): bytes(chr(x))`
martin
A: 

In Python 3.x:

>>> bytes([97])
b'a'
Mark Byers
yeah, whoops, fixed that. Thanks.
Skyler
Will this work for any number 0-255?
Skyler