mwh at python.net
Fri Jul 9 14:15:33 CEST 2004
Andreas Lobinger <andreas.lobinger at netsurf.de> writes:
> Michael Hudson wrote:
> > Andreas Lobinger <andreas.lobinger at netsurf.de> writes:
> >>can anyone here recommend a implementation for bitstreams?
> >>For a project i need to extract bitfields from a file containing
> >>one large bitstream (length >> 1000bit). The bitfields (1bit-24bit)
> >>are not aligned to char boundaries (8bit).
> > Well, a thousand bits really isn't very many. Read the lot and slurp
> > it into a long?
> Thanks to both replies by now. Two points. length>>1000bits means
> that i'm talking about an implementation that runs up to 1000000bits.
> In the moment i'm working with a string in memory and use a state
> maschine to get to the first byte, use string.struct to get
> the word/long containing all bits and a little bit masking.
> There is no real problem writing code for this, but i thought that
> it could be that there are already implementations for bitstreams
> f.e. mpeg-reading, a zlib implementation or other coding/decoding
Not to my knowledge! Such things are generally done by C libraries
that are then wrapped for use by Python, in my experience.
Writing a C extension to do what you need probably isn't amazingly
hard (so long as you don't need bitfields wider than the machine word
size I guess).
8. A programming language is low level when its programs require
attention to the irrelevant.
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html
More information about the Python-list