[Tutor] How to convert a decimal integer into binary

wesley chun wescpy at gmail.com
Wed Sep 20 00:22:43 CEST 2006


> Can anyone help me with teh problem of "converting a decimal number into its
> binary equivalent"??


this sounds like a homework problem, so no code here.  however, the
answer is trivial once you realize that all integers are natively
available in any base, whether it be 2, 8, 10, 16, etc.  since you
want base two, the easiest way to solve your problem is to display
each bit (Binary digIT [or is that BInary digiT?]) one at a time.  the
best way to solve your problem is through an iterative process.  you
may have to tweak your initial solution(s), but you would be well on
your way there!

good luck!
-- wesley

ps. this is a standard programming exercise... it's even in "Core
Python" (see below)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list