[Python-Dev] %b format?

Eric S. Raymond esr@thyrsus.com
Wed, 30 May 2001 17:44:57 -0400


M.-A. Lemburg <mal@lemburg.com>:
> > > I would like to add a "%b" format for converting
> > > numbers to binary format (1's and 0's).  I realize
> > > this isn't a C-ism, but it would be very useful for
> > > teaching purposes, as newcomers find 101101 a lot
> > > easier to understand than 0x2D.
> > 
> > +1.  Didactically pretty useful, and the additional code won't boost
> > global complexity much.
> 
> 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 am thinking of adding a bit field type to mxNumber and have
> the same problem there...

For *this* context, we clearly want mathematical notation; MSB to the right
and no byte-swapping.  After all we'd actually be printing numerals, not 
dumping a bitfield.
-- 
		<a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>

The people of the various provinces are strictly forbidden to have in their
possession any swords, short swords, bows, spears, firearms, or other types
of arms. The possession of unnecessary implements makes difficult the
collection of taxes and dues and tends to foment uprisings.
        -- Toyotomi Hideyoshi, dictator of Japan, August 1588