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?

Weafs.py
  • 22,731
  • 9
  • 56
  • 78
  • 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` – David Heffernan Dec 12 '14 at 10:18
  • Have you tried with `int(address, 16)`? – jeremija Dec 12 '14 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. – David Heffernan Dec 12 '14 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. – jeremija Dec 12 '14 at 10:40

0 Answers0