Base conversion method or module

Mensanator mensanator at aol.compost
Sun Dec 7 23:45:17 EST 2003


>Subject: Re: Base conversion method or module
>From: "Francis Avila" francisgavila at yahoo.com 
>Date: 12/7/2003 8:52 PM Central Standard Time
>Message-id: <vt7pt71h3bsf78 at corp.supernews.com>
>
>
>Jeff Wagner wrote in message ...
>>On Mon, 8 Dec 2003 00:40:46 +0100, "Fredrik Lundh" <fredrik at pythonware.com>
>wrotf:
>>
>>>Jeff Wagner wrote:
>>>
>>>> I found the Python cookbook recipe you were referring to. It is as
>follows:
>>>
>>>(what's wrong with just posting an URL?)
>>
>>What a great idea ;)  ...
>>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286
>
>Hey, I found another one which is the more general "inverse of int/long"
>function I was pining for (and thus learning for the n-th time that one
>should check the cookbook first before reinventing the wheel):
>
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/222109

These are nice, but they're very slow:

For i=2**177149 - 1

224.797000051 sec for baseconvert
202.733999968 sec for dec2bin (my routine)
137.735000014 sec for radix

Compare those to the .digits function that is part of GMPY

0.59399998188 sec

That can make quite a difference when you're running through a couple million
iterations.


>
>For some reason it's in the "Text" category, and uses the term "radix,"
>which is less common than "base".
>
>Hettinger's version (found in the discussion below) is better.
>
>Shouldn't something like this get into the builtins, so we can get rid of
>hex/oct in Python3k?
>--
>Francis Avila



--
Mensanator
Ace of Clubs




More information about the Python-list mailing list