Re: how to convert '\xf0' to 0xf0 ?
- From: Steve Holden <steve@xxxxxxxxxxxxx>
- Date: Fri, 12 Dec 2008 01:28:50 -0500
Looks like you need the struct module. That can convert binary fields of
various lengths into the appropriate Python types, and vice versa.
(4278186224L,)import struct
struct.unpack("L", '\xf0\xf0\xff\xfe')
(-16781072,)struct.unpack("l", '\xf0\xf0\xff\xfe')
regards
Steve
chengang.beijing@xxxxxxxxx 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?
Br, Chen Gang
On Dec 12, 12:40 pm, Steve Holden <st...@xxxxxxxxxxxxx> wrote:
chengang.beij...@xxxxxxxxx wrote:
'\xf0' is the value read from a binary file, I need to change thisIt seems that you want the integer value of a character you read in from
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, 12:06 pm, Tommy Nordgren <tommy.nordg...@xxxxxxxxx> wrote:
On Dec 12, 2008, at 4:48 AM, chengang.beij...@xxxxxxxxx wrote:
int('\xf0',16) doesn't work, any way to do that?Should be int('10',16)
--
http://mail.python.org/mailman/listinfo/python-list
or int('0x10',16)
a file. Is this correct? Note that '\xf0' is the interpreter's way of
representing a one-character string whose only character has the
hexadecimal value f0, because the actual character is not printable: the
backslash has a special meaning in character string literals.
Any one-character string, however, can be converted to the equivalent
integer value using the ord() function. You can convert the other way
using the chr() function:
65ord('A')
'A'chr(65)
240ord('\xf0')
'\xf0'chr(240)
'0xf0'hex(240)
So just apply the ord() function to the character and you'll get its
integer value!
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
.
- References:
- how to convert ‘\xf0' to 0xf0 ?
- From: chengang . beijing
- Re: how to convert ?\xf0' to 0xf0 ?
- From: Tommy Nordgren
- Re: how to convert ‘\xf0' to 0xf0 ?
- From: chengang . beijing
- Re: how to convert '\xf0' to 0xf0 ?
- From: Steve Holden
- Re: how to convert '\xf0' to 0xf0 ?
- From: chengang . beijing
- how to convert ‘\xf0' to 0xf0 ?
- Prev by Date: Re: How do I manually uninstall setuptools (installed by egg)?
- Next by Date: Re: Py_GetPath() C API in python 3
- Previous by thread: Re: how to convert '\xf0' to 0xf0 ?
- Next by thread: Re: how to convert ‘\xf0' to 0xf0 ?
- Index(es):
Relevant Pages
|