[Tutor] RE: Base converter bases 2-62
cino hilliard
hillcino368@hotmail.com
Sat Jun 21 23:23:01 2003
>From: "Jeff Shannon" <jeff@ccvcorp.com>
>To: tutor@python.org
>Subject: Re: [Tutor] RE: Base converter bases 2-62
>Date: Fri, 20 Jun 2003 12:39:38 -0700
>
>cino hilliard wrote:
>
>>>(Of course, as Magnus pointed out, this whole loop can be easily replaced
>>>with 'dec = int(num, r1)' as long as you can cope with a maximum base of
>>>32....
>>
>>Why even mention this? I went to all this trouble for base 32 max? the
>>atol and ltoa in c do this
>>for you to base 36.
>>
>
>Whoops, I *meant* base 36, which is the documented maximum radix for int().
> Python (and I believe the C library functions) don't
That is correct. The macro
#define b2b(b1,b2,num) itoa(strtol(num,NULL,b1),num,b2)
was one of my better acheivements to get a very short c program to convert
base to base.
Of course no quotes here because of the powerful c parser and typing.
Caveat:The integer cannot
exceed 2^31-1 So C won't process b2b(29,10,JEFFSHANNON) properly because
JEFFSHANNON overflows integer.
>distinguish between upper and lower case for these conversions, which means
>that there's 26 alpha + 10 numeric symbols available. It's certainly
>possible to use a wider range of symbols, but
Yes. That is the issue - getting python to do it because of the arbitrary
integer precision.
>probably not of any practical value.
When 64 bit 128 bit and higher processor chips hit the mainstream you may
change your opinion
if you want to get a base 64 representation. My convert.base would do this
quickly if we used
the { and | as the value for 62 and 62 base 10.
>
>Jeff Shannon
>Technician/Programmer
>Credit International
>
>
>
>_______________________________________________
>Tutor maillist - Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
3 3 3 3 3 6 2
(0^0)
2 + 13 + 33 + 43 = 49 = 7 = 343 = 117649
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail