Hexadecimal bytes to integers
Jason Orendorff
jason at jorendorff.com
Thu Mar 14 07:24:04 EST 2002
pekka 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]
Well, if it's a string then you can do this.
>>> message = '0104000000A271'
>>> m = [ int(b, 16) for b in message ]
>>> m
[0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 10, 2, 7, 1]
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list