Is there no function to convert a hex number to decimal?

Thomas Wouters thomas at xs4all.net
Tue Jul 4 06:46:04 EDT 2000


On Mon, Jul 03, 2000 at 12:14:20PM +0200, Markus Gritsch wrote:
> Markus Gritsch wrote:

> > Although there are several built in functions to convert numbers from
> > decimal to hex or oct, it seems that there is no function which can do
> > the same in the reverse direction.  Of course I can write 0xff, but
> > what should I do, if I have a string containing a hex value?

> I found the solution in the string module:
> atoi (s[, base]) and atol (s[, base])

> BTW, these functions will become obsolete in python 2.0, because there
> will be an optional "base" argument to the built-in functions long() and
> int()

Before we get a long discussion about backwards compatibility ;) I'd like to
point out that the string.ato* functions might, in the strict sense, become
obsolete, but that doesn't mean they are going to disappear. Rather, the
string module is rewritten to use the builtin functionality: string.atoi()
becomes a wrapper for int().

I doubt the string module will disappear before Py3K, and probably not until
way after Py3K to boot.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list