decimal to binary

John Hunter jdhunter at ace.bsd.uchicago.edu
Fri Jul 25 14:37:19 CEST 2003


>>>>> "manuel" == manuel  <manuelbastioniNOSPAM at tin.it> writes:

    manuel> How to convert a decimal to binary ?  thx,

    1.  Divide the "desired" base (in this case base 2) INTO the
        number you are trying to convert.

    2.  Write the quotient (the answer) with a remainder like you did
        in elementary school.

    3.  Repeat this division process using the whole number from the
        previous quotient (the number in front of the remainder).

    4.  Continue repeating this division until the number in front of
        the remainder is only zero.

    5.  The answer is the remainders read from the bottom up.

Is this what you meant :-)?  Or do you want to convert an integer to a
binary string in python?  If the latter, see the struct module


  http://www.python.org/doc/current/lib/module-struct.html

John Hunter





More information about the Python-list mailing list