Python - Converting Hex to INT/CHAR

后端 未结 6 2143
你的背包
你的背包 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条回答
  •  -上瘾入骨i
    2020-12-10 17:19

    A simple way

    >>> s = 'C0A80026'
    >>> map(ord, s.decode('hex'))
    [192, 168, 0, 38]
    >>> 
    

    if you prefer list comprehensions

    >>> [ord(c) for c in s.decode('hex')]
    [192, 168, 0, 38]
    >>> 
    

提交回复
热议问题