Noble Dinasaur
Noble Dinasaur

Reputation: 107

Python converting hex string to hex little endian byte code

I'm trying to do this

pack("<Q", 0x401a12)

It works as it is, but I need pack() to take string hex code

addr = "0x401a12" # some hex from dump
pack("<Q", addr)

Any help?

Upvotes: 2

Views: 10308

Answers (1)

juanpa.arrivillaga
juanpa.arrivillaga

Reputation: 95993

You can use int to convert to the corresponding integer:

struct.pack('<Q', int('0x401a12', base=16))

Upvotes: 2

Related Questions