Re: how to convert '\xf0' to 0xf0 ?

2008-12-11 Thread Steve Holden
Looks like you need the struct module. That can convert binary fields of various lengths into the appropriate Python types, and vice versa. >>> import struct >>> struct.unpack("L", '\xf0\xf0\xff\xfe') (4278186224L,) >>> struct.unpack("l", '\xf0\xf0\xff\xfe') (-16781072,) >>> regards Steve cheng

Re: how to convert '\xf0' to 0xf0 ?

2008-12-11 Thread Stephen Thorne
On 2008-12-11, chengang.beij...@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)

Re: how to convert '\xf0' to 0xf0 ?

2008-12-11 Thread Benjamin Kaplan
On Fri, Dec 12, 2008 at 12:28 AM, 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? > Is that supposed to be a single integer or 4 integers? Either way, you'd use a for loop to iterate over each characte

Re: how to convert '\xf0' to 0xf0 ?

2008-12-11 Thread chengang . beijing
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? Br, Chen Gang On Dec 12, 12:40 pm, Steve Holden wrote: > chengang.beij...@gmail.com wrote: > > '\xf0' is the value read from a binary file, I need to change this > > ki

Re: how to convert ‘\xf0' to 0xf0 ?

2008-12-11 Thread peterca...@gmail.com
On Dec 12, 4:48 am, chengang.beij...@gmail.com wrote: > int('\xf0',16) doesn't work, any way to do that? hex(ord('\xf0')) HTH, Pete -- http://mail.python.org/mailman/listinfo/python-list

Re: how to convert '\xf0' to 0xf0 ?

2008-12-11 Thread Steve Holden
chengang.beij...@gmail.com wrote: > '\xf0' is the value read from a binary file, I need to change this > kinds strings to int for further processing... > if it is in C, then '\xf0' is an integer and it can be handled > directly, but in python, it is a string. > > and both int('10',16) and int('0x1

Re: how to convert ‘\xf0' to 0xf0 ?

2008-12-11 Thread chengang . beijing
'\xf0' is the value read from a binary file, I need to change this kinds strings to int for further processing... if it is in C, then '\xf0' is an integer and it can be handled directly, but in python, it is a string. and both int('10',16) and int('0x10',16) returns 16. Br, Chen Gang On Dec 12,

Re: how to convert ‘\xf0' to 0xf0 ?

2008-12-11 Thread Tommy Nordgren
On Dec 12, 2008, at 4:48 AM, chengang.beij...@gmail.com wrote: int('\xf0',16) doesn't work, any way to do that? -- http://mail.python.org/mailman/listinfo/python-list Should be int('10',16) or int('0x10',16) -- "Home is not where you

how to convert ‘\xf0' to 0xf0 ?

2008-12-11 Thread chengang . beijing
int('\xf0',16) doesn't work, any way to do that? -- http://mail.python.org/mailman/listinfo/python-list