0

I'm having trouble converting a list of bytes to string. Whenever I apply:

char = chr(int(byte,2))

I get the right character, but when I concatenate it with a string:

string+= char

I get weird symbols:

÷ãЪþãÝ¿HÛaû³ªI|ÁŸì½ XG„8jRTa!qÚhϹ4ý{B

After Googling, I found out that I have to convert it to UTF-8 using string.encode('utf-8'), but after converting it, I get something like this:

b'string'

I couldn't find a way to remove the b'' from the output

string=""
for byte in bytes:
    char = chr(int(byte,2))
    string+=char

print(string.encode('utf-8'))
#output : b'my string'

print(string)
#output :  ÷ãЪþãÝ¿HÛaû³ªI|ÁŸì½ XG„8jRTa!qÚhÏ.....

I'm looking for a way to convert my bytes to a normal string

David Buck
  • 3,752
  • 35
  • 31
  • 35
  • 3
    Does this answer your question? [Convert bytes to a string](https://stackoverflow.com/questions/606191/convert-bytes-to-a-string) – LucG Apr 13 '20 at 11:00
  • @LucG thanks for answering, unfortunately, i read the post before and i reviewed it again now, the list i have contains bytes, after converting them to chars, then concatenate them in a string, i use encode and then i get the b'string' output, if i use decode again on them (as mentioned in the post) i will get those weird symbols again. even converting the byte list to ints and then `"".join(map(chr, bytes_data))` will give me the same weird symbols too. – Rafiq n Apr 13 '20 at 15:40
  • after trying to solve it again, i tried to run it with cmd (i was using pycharm), with cmd it gives me the right output, but pycharm it gives me wrong output – Rafiq n Apr 13 '20 at 16:40

0 Answers0