Hello, I have a question about arbitrary bit packing functions.
I have recently needed to store data in a binary format, and spent quite some
time trying to find a way to pack and unpack with the pack() and unpack()
functions. In the end, I found a way to do what I needed with vec(). The only
reason that was possible was because I was storing/retrieving nybbles and
bytes, since vec() only works on a power of two number of bits. But, what if I
had needed to store/retrieve some arbitrary number of bits?
Here is a test case, I am wondering how some of you would address this
challenge.
Store / Retrieve four (4) fields (2 bits, 6 bits, 3 bits, 5 bits) into 2 bytes
Example:
## bit string: 10 101010 110 01110
custom_pack(2,42,6,14) == \xAACE
custom_unpack(\xAACE) == (2,42,6,14)
I appreciate any guidance you may have.
---
Stephen ~runester~ Jarjoura
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm