[Python-ideas] Add a builtin method to 'int' for base/radix conversion

MRAB python at mrabarnett.plus.com
Mon Sep 14 15:37:20 CEST 2009


Lie Ryan wrote:
> Yuvgoog Greenle wrote:
>> Btw, when you say translation table, do you mean just a string? 
>> Because a translation table would need to be continuous from 0 to the 
>> base so a real dicitionary-esque table may be overkill. The only 
>> advantage of a table might be to convert certain digits into multiple 
>> bytes (some sort of ad-hoc unicode use case?).
>>
> 
> If the translation table is limited to a string, the function would be 
> very limited. For example, it might be useful to use base-change 
> function to convert between an IPv4 address and integer. The common 
> representation of IPv4 address uses base-255 "number" 
> (0.0.0.0-255.255.255.255)
> 
If the translation table is a dict then you can decode both 'A' and 'a'
to 10. You could, of course, permit either a string or a dict, with a
string being converted to a dict.



More information about the Python-ideas mailing list