Search code examples
arrayspython-3.xhex

bytearray: How to split hexadecimal digits and preserve type


This does not give the expected result:

import base64

k = 'EQAAAE4kAARA'
l = bytearray(base64.b64decode(k))
m = l.hex()
m

Output:

'110000004e24000440'

I intend to split the hexadecimal string at the 8th digit, combine it, flip it (MSB) and convert to decimal:

n = [d for d in str(n)]
o = "".join(n[:7])
p = int(o)
p = bytearray(p)
q = int.from_bytes(p, byteorder='little')
q

Output:

0

I am supposed to get 17 as the decimal conversion from 11000000 hexadecimal.


Solution

  • >>> int.from_bytes(binascii.unhexlify('11000000'), 'little')
    17