tags:

views:

223

answers:

1

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 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
+2  A: 

The hex function converts integers to their hexadecimal representation:

>>> a = 123
>>> hex(a)
'0x7b'
Roberto Bonvallet
I tried that already and moved on due to this error, TypeError: hex() argument can't be converted to hex
Recursion
@Recursion: If you find an error, try to find out about the cause; randomly trying other methods is not going to help you in the long run.
kaizer.se
I don't have paranormal powers, but I suspect you're trying to pass a string to `hex`. Try `hex(int(a))` or post some actual code.
Roberto Bonvallet