1

i have the below posted binary contents. i would like to convert them into a readible text/string. i found some questions related to the same issue and they suggested that the binary contents must be decoded to utf-8 or ascii. however, i tried both and i got the following errors respectively:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 54: invalid start byte
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 54: ordinal not in range(128)

please let me know how to decode the below posted binary

binary contents:

b"MM\x00*\x00\x00\x00\x08\x00\x12\x01\x00\x00\x03\x00\x00\x00\x01\x00$\x00\x00\x01\x01\x00\x03\x00\x00\x00\x01\x00%\x00\x00\x01\x02\x00\x03\x00\x00\x00\x01\x00 \x00\x00\x01\x03\x00\x03\x00\x00\x00\x01\x80\xb2\x00\x00\x01\x06\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01\x11\x00\x04\x00\x00\x00\x01\x00\x00\x01\xee\x01\x15\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01\x16\x00\x03\x00\x00\x00\x01\x00%\x00\x00\x01\x17\x00\x04\x00\x00\x00\x01\x00\x00\x00 \x01\x1a\x00\x05\x00\x00\x00\x01\x00\x00\x00\xe8\x01\x1b\x00\x05\x00\x00\x00\x01\x00\x00\x00\xf0\x01(\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01S\x00\x03\x00\x00\x00\x01\x00\x03\x00\x00\x83\x0e\x00\x0c\x00\x00\x00\x03\x00\x00\x00\xf8\x84\x82\x00\x0c\x00\x00\x00\x06\x00\x00\x01\x10\x87\xaf\x00\x03\x00\x00\x004\x00\x00\x01@\x87\xb0\x00\x0c\x00\x00\x00\x03\x00\x00\x01\xa8\x87\xb1\x00\x02\x00\x00\x00.\x00\x00\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01@0\x03\x80T\x81\xa0\x00@/\xfb\x9e\xac\xf4S\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00A&\xb9\xf8\x04\xce4\x9bAYYY\xd7\xe3ZB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x0c\x04\x00\x00\x00\x00\x01\x00\x01\x04\x01\x00\x00\x00\x01\x00\x01\x08\x02\x00\x00\x00\x01\x00\x01\x04\x02\x87\xb1\x00%\x00\x00\x08\x01\x87\xb1\x00\x06\x00&\x08\x06\x00\x00\x00\x01#\x8e\x08\x08\x00\x00\x00\x01\x00\x01\x08\t\x87\xb0\x00\x01\x00\x00\x08\n\x87\xb0\x00\x01\x00\x01\x08\r\x87\xb0\x00\x01\x00\x02\x0c\x00\x00\x00\x00\x01\x0f\x11\x0c\x04\x00\x00\x00\x01#)AXT\xa6@\x00\x00\x00AXT\xa6@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Popular Visualisation Pseudo Mercator|WGS 84|\x00x^\xed\xc3\x01\t\x00\x00\x0c\x03\xa05_\xb5G[\x8e\x83\x82\xbd\xa4\xaa\xaa\xaa\xaa\xaa\x0f\x0e]\x13|'"
LetsamrIt
  • 3,653
  • 7
  • 39
  • 72
  • If you don't know the encoding, you can't decode it, I'm afraid. For sure, it's not UTF-8. What do you want to do with the results? – Ulrich Eckhardt Mar 30 '22 at 10:28
  • @UlrichEckhardt it is a tiff file / image – LetsamrIt Mar 30 '22 at 10:31
  • @UlrichEckhardt what other deocoding methods could be please? – LetsamrIt Mar 30 '22 at 10:31
  • Most file formats have a specific structure so "decoding" them will depend on their content which may not be textual at all like an image or sound. – martineau Mar 30 '22 at 10:36
  • 4
    Ah. I think we have a terminology problem here. If you take bytes and decode them according to their encoding, you get a text string. However, you don't have bytes that represent any text, so that's not the option. Rather, you need a textual representation for raw binary data. For that, you could use base64, for example. – Ulrich Eckhardt Mar 30 '22 at 10:37
  • @UlrichEckhardt can you please provide an example for base64? – LetsamrIt Mar 30 '22 at 10:39
  • Does this answer your question? [Encoding an image file with base64](https://stackoverflow.com/questions/3715493/encoding-an-image-file-with-base64) – Ulrich Eckhardt Mar 30 '22 at 10:39
  • BTW: I just typed "[python] base64" into the search bar above. – Ulrich Eckhardt Mar 30 '22 at 10:39
  • You would also need to show the code that leads to that error, and the relevant traceback(s). – AKX Mar 30 '22 at 11:44

0 Answers0