hex and little endian
Matteo Memelli
cipher at be4mind.com
Sat Dec 13 11:34:35 EST 2003
Il Sat, 13 Dec 2003 13:13:24 +0100, Fredrik Lundh ha scritto:
> Matteo Memelli wrote:
>
>> I'm trying to convert an hex address like 0xbfffe2f1 in little endian
>> format \xf1\xe2\xff\xbf. Is there any funcion that can make this?
>
>>>> import struct
>>>> struct.pack("<i", 0xbfffe2f1)
> '\xf1\xe2\xff\xbf'
>
> (see the library reference for details)
>
>> Whe I try to code somethig like this:
>> "\x%s\x%s\x%s\x%s" % (string1, string2, string3, string4)
>> I obtain this error:
>> ValueError: invalid \x escape
>> and if I escape the charachter "\" making something like this:
>> "\\x%s\\x%s\\x%s\\x%s" % (string1, string2, string3, string4)
>> It works but the resulting string is not an hex representation
>
> "\x" is used in string literals; it has no special meaning when it's
> used in a string object.
>
> </F>
Thanks you guys :)
Matte
More information about the Python-list
mailing list