5 ms·
This is a good article, but what I've been struggling with recently is dealing with literal binary data in Python. What I mean by that is I literally have data
by robzyb 11y ago
This is a good article, but what I've been struggling with recently is dealing with literal binary data in Python.
What I mean by that is I literally have data stored in memory, and I want to deal with it in arbitrary groups of bits.
Sometimes 1 bit, sometimes 7 bits, rarely 13 bits.
My Google's haven't turned up much precedent.
</off topic complaint>
- RazerM 11y agoHave you tried bitarray[1]? [1]: https://pypi.python.org/pypi/bitarray https://pypi.python.org/pypi/bitarray
- robzyb 11y agoIt was that easy? Man. Looking forward to giving these a shot...
- toyg 11y agoObligatory XKCD: https://xkcd.com/353/ https://xkcd.com/353/
- tonyarkles 11y agoI've used it quite heavily to parse data that comes in 85- and 1275-bit chunks and it works awesome. Edit: sorry, it was bitstring, not bitarray. bitstring.BitArray :).
- _yy 11y ago+1 from me. Excellent library
- switch007 11y agoAlso https://pythonhosted.org/bitstring https://pythonhosted.org/bitstring