[Tutor] How to convert an integer into a binary?

steve lonetwin@yahoo.com
Wed, 8 Aug 2001 16:19:23 +0530


On Wednesday 08 August 2001 13:56, you wrote:
> On Wed, Aug 08, 2001 at 03:36:04PM +0900, Haiyang wrote:
> > How can I convert an interger into a binary code in Python?
>
> Hello!
>
> This should become a faq ;-)

 And also should be put on Useless, Rob ???

Peace
Steve
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> import sys
> e=3D[]
> try:
> =09z=3Dint(raw_input("Number?\n> "))
> except:
> =09print "Need a number."
> =09sys.exit(1)
> while (z > 0):
> =09if (z & 1) =3D=3D 1:
> =09=09e.append(1)
> =09else:
>  =09=09e.append(0)
>         z=3Dz>>1
> e.reverse()
> print e

--=20
-----------------------------------------
bug, n:
=09=09A son of a glitch.
-----------------------------------------