Trouble converting hex to decimal?

Steve Holden steve at holdenweb.com
Sat Feb 5 12:02:16 EST 2005


Pedro Werneck wrote:

> Hi
> 
> The problem is that '\x00' is a escape sequence... 
> 
> Try something like this:
> 
> 
> 
>>>>x = '\x00'
>>>>int(repr(x)[3:-1], 16)
> 
> 0
> 
>>>>x = '\x15'
>>>>int(repr(x)[3:-1], 16)
> 
> 21
> 
> 
> 
> 
> On Sat, 05 Feb 2005 06:51:32 -0700
> Earl Eiland <eee at nmt.edu> 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
>>
Talk about making things difficult!

  >>> x = '\x00'
  >>> ord(x)
0
  >>> x = '\x15'
  >>> ord(x)
21
  >>>

regards
  Steve
-- 
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005                      http://www.pycon.org/
Steve Holden                           http://www.holdenweb.com/



More information about the Python-list mailing list