Trouble converting hex to decimal?
Alan McIntyre
alan.mcintyre at esrgtech.com
Sat Feb 5 09:12:42 EST 2005
Earl,
Try this:
>>> ord('\x00')
0
or:
>>> import struct
>>> struct.unpack('b', '\x00')
(0,)
If you're needing to pull values out of multiple bytes (shorts, longs,
floats, etc.), have a look at the struct module. Here's an example:
>>> struct.unpack('f', '\x00\x00(B')
(42.0,)
Hope this helps,
Alan
Earl Eiland wrote:
> I'm trying to process the IP packet length field, as recorded by pcap
> (Ethereal) and recovered using pcapy. When I slice out those bytes, I
> get a value that shows in '\x00' format, rather than '0x00'. Neither
> int() nor eval() are working. How do I handle this?
>
> Earl Eiland
>
More information about the Python-list
mailing list