1

I have a json with data="90ab"

unpack = json.loads(content)
data = unpack['data']
data_byte=bytearray.fromhex(data)

I want data_byte to be an array of bytes [byte1 byte2], with byte1=0x90, and byte2=0xab I need help, because what I tried doesn't seem to work Thanks

user3278790
  • 75
  • 1
  • 3
  • 9

1 Answers1

1

It depends on python version, so the way to decode hex data may vary:

data="90ab"

Since Python 2.7 and 3.0:

bytearray.fromhex(data)

Python 2.6 and before:

data.decode("hex")
Oleh Rybalchenko
  • 6,998
  • 3
  • 22
  • 36