Python:列表到十六进制

时间:2009-12-16 18:02:39

标签: python hex

我正在编写一个小的取证python应用程序,但我无法将List条目转换为Hex。我已经尝试了编码/解码方法,但得到了伪造的转换或奇数长度的字符串类型错误。我已粘贴下面的代码,正如您所见,我需要十六进制的地址,所以我可以添加计数。

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 个答案:

答案 0 :(得分:2)

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

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