Skip to main content

Bit-packing and unpacking integer fields

Project description

bitpacking

Bit-packing and unpacking integer fields.

PyPI - Python Version PyPI PyPI - Downloads Commits since latest release

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitpacking-0.0.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bitpacking-0.0.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file bitpacking-0.0.1.tar.gz.

File metadata

  • Download URL: bitpacking-0.0.1.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

Hashes for bitpacking-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5c630dac6ca776dbde271bb5140b090317915e4ff97083fea373cae62f6509e1
MD5 843f89e2411fc5da4bb2fe9d733167eb
BLAKE2b-256 3dd3887461a3914468fc7df4c4717bad97e607f91ade17ad6e00341a98e4103e

See more details on using hashes here.

File details

Details for the file bitpacking-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: bitpacking-0.0.1-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

Hashes for bitpacking-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c26629f0c4a04d4b2949ed68baad3454ba5a5e1f5f92dfe0c63e4e721d609215
MD5 159f0cb0a68acd497c0f1219d04b7de1
BLAKE2b-256 f30db9b2436f7f34fddb273cfa07f9f072000bd7138504a438e0c65048eeeb38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page