Convert Hex to UTF-8



  • There's a line: '0x0F 0x00 0x39 0x32 0x2E 0x30 0x2E 0x34 0x35 0x31 0x35 0x00 I want to convert it into a readable format. I'm trying to do this:

    fff = '0x0F 0x00 0x39 0x32 0x2E 0x30 0x2E 0x34 0x35 0x31 0x35 0x00'
    bytes_object = bytes.fromhex(fff)
    print(bytes_object.decode("UTF-8"))
    

    I'm getting a trailer.

    Traceback (most recent call last):
      File ".../check.py", line 14, in <module>
        bytes_object = bytes.fromhex(fff)
    ValueError: non-hexadecimal number found in fromhex() arg at position 1
    

    Does anyone have any idea what I'm doing wrong and how to get the necessary data out of this hex? Online converter says there must be this value: 92.0.4515



  • Take the gaps away and 0x From the line, first:

    fff = '0x0F 0x00 0x39 0x32 0x2E 0x30 0x2E 0x34 0x35 0x31 0x35 0x00'
    bytes_object = bytes.fromhex(fff.replace(' ', '').replace('0x', ''))
    print(bytes_object.decode("UTF-8"))
    

    But still there at the beginning. 0F and 00 stay at the end. 00they are not converted into printed symbols:

    �92.0.4515�
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2