Hexadecimal bytes to integers

gbreed at cix.compulink.co.uk gbreed at cix.compulink.co.uk
Thu Mar 14 09:07:56 EST 2002


pekka niiranen wrote:

> How can I convert messages below to list of bytes:
> 
> message = 0x01040000000271
> or
> message = 0104000000A271
> to
> m = [0,1,0,4,0,0,0,0,0,0,0,0,'A',2,7,1]

You're showing nybbles, not bytes.  For bytes,

[int(message[i:i+2], 16) for i in range(2, len(message),2)] 

or

[int(message[i:i+2], 16) for i in range(0, len(message),2)]



More information about the Python-list mailing list