Converting integer to binary representation

Anton Vredegoor anton at vredegoor.doge.nl
Wed Dec 17 11:39:52 EST 2003


anton at vredegoor.doge.nl (Anton Vredegoor) wrote:

> >>> list(10)
> >>> [True,False,True,False]

Sorry,	I was dead wrong here, or maybe not, it all depends on the
future.

The code below here would make the positions of the booleans
correspond to the powers of two: 

 >>> list(10)
 >>> [False,True,False,True]

But the other interpretation has some merit too since it corresponds
to the way we use strings to denote numbers. There is a choice between
left-to-right and right-to-left here, analogous to the "most
significant bit" issue.

Because these interpretations are more or less equally valid, there is
no obvious way of doing it. Making an explicit choice here would be
good since that would remove the ambiguity. Guido could use his time
machine to make one of these alternatives the obvious way to do it.

Anton





More information about the Python-list mailing list