Most efficient way of storing 1024*1024 bits

Ben Sizer kylotan at gmail.com
Fri Nov 4 05:26:19 EST 2005


Tom Anderson wrote:
> On Wed, 2 Nov 2005, Dan Bishop wrote:
>
> > Tor Erik Sønvisen wrote:
> >
> >> I need a time and space efficient way of storing up to 6 million bits.
> >
> > The most space-efficient way of storing bits is to use the bitwise
> > operators on an array of bytes:
>
> Actually, no, it's to xor all the bits together and store them in a single
> boolean.

I'd use 'or' rather than 'xor'. The or operator is more likely to yield
a '1' at the end of it, and a 1 is narrower than a 0, obviously making
it more efficient to store.

-- 
Ben Sizer




More information about the Python-list mailing list