how to convert '\xf0' to 0xf0 ?

Stephen Thorne stephen at thorne.id.au
Fri Dec 12 01:01:48 EST 2008


On 2008-12-11, chengang.beijing at gmail.com wrote:
> Hi,
> 
> ord('\xf0') works and it only works for char. Do you know any way to
> convet
> '\xf0\xf0' and '\xf0\xf0\xff\xfe' to integer?

Perhaps you want the 'struct' module.

>>> struct.unpack('!hi', '\xf0\xf0\xf0\xf0\xff\xfe')
(-3856, -252641282)

help(struct) for more information
-- 
Regards,
Stephen Thorne
Development Engineer
NetBox Blue - 1300 737 060

Scanned by the NetBox from NetBox Blue
(http://netboxblue.com/)




More information about the Python-list mailing list