2

how to use the hex value stored in an argument to convert into decimal in python

data_size = 3#number of bytes of data to read
offset = 0 #start offset

while offset <= 784128:
     for i in range (0,784128):
      Target_file.seek(offset)
      s = Target_file.read(data_size)
      i = hex (s)
      str(i)
      output.write(str(i))
      offset = offset + 3

The above is the program I tried to input hex value into an argument called 's' and tried to convert the value into decimal value and write it into a file.

but the error I am getting is

i = hex (sector_header)
TypeError: hex() argument can't be converted to hex
user2628659
  • 25
  • 2
  • 7

1 Answers1

1
i = hex (sector_header)
TypeError: hex() argument can't be converted to hex

You are trying to convert it to a hex value.

use

int("ff", 16)
i = int(s, 16)

This answer explains it.

Community
  • 1
  • 1
  • I tried the code above but I get this error now i = int (s, 16) ValueError: invalid literal for int() with base 16: '\xa6\xaa\xab' – user2628659 Jul 29 '13 at 02:13