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
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)
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
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
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
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
'\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,
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
int('\xf0',16) doesn't work, any way to do that?
--
http://mail.python.org/mailman/listinfo/python-list