[Tutor] hexadecimal to decimal

Karl Pflästerer sigurd at 12move.de
Fri Mar 12 14:53:09 EST 2004


On 11 Mar 2004, Philippe Strauss <- philippe.strauss at practeo.ch wrote:

> Python 2.2.1 (#1, Apr 21 2002, 08:38:44)

Did you read about the buffer overflow in Python 2.2?  I'm not sure if it
was fixed in 2.2.1.

>>>> print int('0xe7')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ValueError: invalid literal for int(): 0xe7

> what's the trick?

>>> print int('0xe7', 16)
231

I.e. tell int() what base to use (10 is the default base).

>>> int('10')
10
>>> int('10', 16)
16



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list