[Python-Dev] %b format?

Tim Peters tim.one@home.com
Wed, 30 May 2001 17:50:31 -0400


[Greg Wilson]
> I would like to add a "%b" format for converting
> numbers to binary format (1's and 0's).

-0, due to compound lumpiness:  hex() is to %x is to __hex__ as oct() is to
%o is to __oct__ as nothing is to %b is to nothing.  In that respect it's
unfortunate that Python has distinct nb_oct and nb_hex slots in the
PyNumberMethods struct (as opposed to a single parameterized "convert to
base N string" method).

[MAL]
> Good idea. The only question I have is: in which order will
> you print the 0s and 1s (MSB->LSB, LSB->MSB, little/big endian) ?

I'm sure Greg has in mind only integers, in which case %x and %o already
give the only useful <wink> answer.