0

I have a input JSON file which include data with String like "Address": "0x33". I would like to use this data to open my raw data file and seek to the file location.

infile.seek(0x30,0)

How could I convert the input data to a hex value and let my seeking address flexiable?

address="0x30"
infile.seek(address,0)

How to convert string "0x30" to a hex value 0x30?

4
  • 3
    FWIW, you would not convert a string to a hex value. You would convert a string to an integer value. Hex is just a representation. Remember that 0x30 == 48 Commented Dec 12, 2014 at 10:18
  • Have you tried with int(address, 16)? Commented Dec 12, 2014 at 10:30
  • @jeremija That won't work because of the 0x. The answer can be found at the dupe. Follow the link for enlightenment. Commented Dec 12, 2014 at 10:34
  • @david seems to work fine for me. int('deadbeef', 16) == int('0xdeadbeef', 16) evaluates to True in both python 2.7.6 and python 3.4.0 on my machine. Commented Dec 12, 2014 at 10:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.