base converter

David C. Ullrich ullrich at math.okstate.edu
Thu Jun 14 15:11:19 CEST 2001


On Wed, 13 Jun 2001 22:01:08 GMT, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:

>Jeroen Wolff wrote:
>> I looked on the net for a baseconverter written in python. Is there
>> any? Something like:
>>
>> BaseConvert(20,2) --> "10100"
>
>def BaseConvert(x, b):
>    out = ""
>    while x:
>        x, d = divmod(x, b)
>        out = str(d) + out
>    return out
>
>(why has decimal to binary conversion suddenly turned into a
>FAQ the last few months? 

Because it's recently been determined that using binary is
more "logical"? (Maybe not...)

> it wasn't this way in the old days,
>and I cannot remember ever having to output things as binary
>numbers in a real-life project...  can anyone explain?)
>
></F>
>
>



David C. Ullrich
*********************
"Sometimes you can have access violations all the 
time and the program still works." (Michael Caracena, 
comp.lang.pascal.delphi.misc 5/1/01)



More information about the Python-list mailing list