Bit-packing and unpacking integer fields
Project description
bitpacking
Bit-packing and unpacking integer fields.
Installation
bitpacking is available on pypi:
pip install bitpacking
Example
Basic usage example (can be found in examples/pack_unpack.py):
from bitpacking import bitpack, bitunpack
ints = [
1, 2, 0, 0,
3, 0, 0, 0,
0, 0, 0, 0,
4, 0, 0, 0,
0, 0, 0, 0,
0, 5, 0, 6,
]
chunks = list(bitpack(fields=ints, field_width=3, chunk_width=64))
print(f"Bit-packed chunks: {chunks}")
fields = list(bitunpack(chunks=chunks, chunk_width=64, field_width=3))
print(f"Unpacked fields: {fields}")
Output:
Bit-packed chunks: [9223372311732695057, 194]
Unpacked fields: [1, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Notice that the fields list has more entries than the initial ints list.
This is because the leading zeros in the last chunk (194) are unpacked into
"empty" fields.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitpacking-0.1.0.tar.gz.
File metadata
- Download URL: bitpacking-0.1.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2982c64c855575c2ad13c2cffaa7e25b3d3b81cbdf7badc1b691e8146d0f5569
|
|
| MD5 |
7c642dc0431b771e9810651a786f530c
|
|
| BLAKE2b-256 |
de181c63e92742b77eeee8b754b58fb44b04b8189fa1af7a953fb16f7d2a3a2f
|
File details
Details for the file bitpacking-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bitpacking-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a6714ebdf85b248eb70cdb98fb94bc0fcb519393cacd0537b159634a233c35c
|
|
| MD5 |
8baa9acdd5c3b63560718d1b41827419
|
|
| BLAKE2b-256 |
a23249375a36628689faea48b21ca40229907d8042c148c2ae3f41f5b3d3d2a6
|