Python - Converting Hex to INT/CHAR

后端 未结 6 2146
你的背包
你的背包 2020-12-10 16:54

I am having some difficulty changing a hex to an int/char (char preferably). Via the website; http://home2.paulschou.net/tools/xlate/ I enter the hex of C0A80026 into the he

6条回答
  •  温柔的废话
    2020-12-10 17:19

    For converting hex-string to human readable string you can escape every HEX character like this:

    >>> '\x68\x65\x6c\x6c\x6f'
    'hello'
    

    from string you can easily loop to INT list:

    >>> hextoint = [ord(c) for c in '\x68\x65\x6c\x6c\x6f']
    >>> _
    [104, 101, 108, 108, 111]
    

    Your example:

    >>> [ord(c) for c in '\xC0\xA8\x00\x26']
    [192, 168, 0, 38]
    

提交回复
热议问题