Bitsets in Python

Graham Fawcett graham__fawcett at hotmail.com
Thu Feb 5 15:03:01 EST 2004


matt_crypto at yahoo.co.uk (Matt) wrote in message news:<94b59a36.0402050550.442a93d1 at posting.google.com>...
> Josiah Carlson <jcarlson at nospam.uci.edu> wrote:
> > >   does Python have any native support for bitsets? I dont seem to see
> > >   anything in the standard library?
> > 
> > What do you mean 'bitsets'?  Give a list of functionality of your 
> > 'bitsets', and it will be easy for us to tell you whether Python 
> > includes it.
> 
> BitSets crop up in (at least) C++ and Java. They allow you operate on
> a sequence of bits using a friendlier interface than hacking about
> with ^,|,& et al on integers. The Java BitSet interface:
> 
> http://java.sun.com/j2se/1.4.1/docs/api/java/util/BitSet.html
> 
> I can't find anything like it in the standard library (If I've
> overlooked it, I'd be chuffed to find out I'm wrong!). The OP might
> find the following Cookbook recipe useful, though:

Depending on your needs, you might find Sam Rushing's npstruct module
to be of use.

npstruct: An extension module useful for parsing and unparsing binary
data structures. Somewhat like the standard struct module, but with a
few extra features (bitfields, user-function-fields, byte order
specification, etc...) and a different API more convenient for
streamed and context-sensitive formats like network protocol packets,
image and sound files, etc...

http://nightmare.com/software.html

-- Graham



More information about the Python-list mailing list