Reading hex to int from a binary string
jack at 0x6a.com
Fri Oct 9 15:32:56 CEST 2009
> Hi all,
> I read data from a binary stream, so I get hex values as characters
> (in a string) with escaped x, like "\x05\x88", instead of 0x05.
> I am looking for a clean way to add these two values and turn them
> into an integer, knowing that calling int() with base 16 throws an
> invalid literal exception.
> Any help appreciated, thanks.
Check out the ord() function.
x = '\x34'
Also, if you, lets say read(4), and end up with `x = '\x05\x41\x24\x00'
you can use x[i] to address each character. So if you
That should be enough to get you started in the right direction.
More information about the Python-list