Python: List to Hex
I am writing a small forensics python app and I am having trouble converting a List entry to Hex. I have tried the encode/decode methood but get bogus conversions or odd-length string Type Errors. I have pasted the code below, and as you can see I need the address in hex, so I can add the count to it.
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 te开发者_如何学Pythonmp[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
The hex
function converts integers to their hexadecimal representation:
>>> a = 123
>>> hex(a)
'0x7b'
精彩评论