代码之家  ›  专栏  ›  技术社区  ›  Recursion

python:列表到十六进制

  •  -1
  • Recursion  · 技术社区  · 15 年前

    我正在编写一个小型的取证python应用程序,在将列表项转换为十六进制时遇到了问题。我尝试过编码/解码方法,但得到了伪造的转换或奇数长度的字符串类型错误。我已经粘贴了下面的代码,正如您所看到的,我需要十六进制的地址,这样我就可以向它添加计数。

    def location_finder(line):
    count = 0
    temp = line.split(' ') #3 Tokenizes first element, by first space
    address = str(temp[0].split(':')) # Take's : off of first element(address)
    print address, "dog"
    address = address.decode("hex")
    print address, "cat"
    #print temp[0]
    line_address = temp[0].upper()
    for addy in temp:
    
        if addy == "ffd8":
            return (address+count)
        if addy == "ffd9":
            return (address+count)
    
    count = count + 1
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   Roberto Bonvallet    15 年前

    这个 hex 函数将整数转换为十六进制表示形式:

    >>> a = 123
    >>> hex(a)
    '0x7b'