[Tutor] Printing byte arrays
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Mar 7 14:46:50 EST 2022
On 07/03/2022 13:02, Ludo Joris wrote:
>>>> b = [int(e,2) for e in a]
>>>> b
> [0, 224, 224, 0, 224, 224, 32,...
>>>> c = bytes([int(e,2) for e in a])
>>>> c
> b'\x00\xe0\xe0\x00\xe0\xe0 \xc0...
In UTF8/ASCII decimal 32 is the space character.
I'm surprised you aren't getting other random characters
and numbers too. You just got 'lucky' in that the
only printable values were spaces.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list