Python: 列表转十六进制
我正在写一个小的取证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 个回答
2
hex
函数的作用是把整数转换成十六进制的表示方式:
>>> a = 123
>>> hex(a)
'0x7b'