Skip to main content

Bit-packing and unpacking integer fields

Project description

bitpacking

Bit-packing and unpacking integer fields.

PyPI - Python Version PyPI

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.2.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.2-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bitpacking-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 40fe3cf6c993b61347616f0ac9e9946e635f9cfeaa03039bf2477460348769b7
MD5 3e800c4d6b185fe61411d7b8232c3e4f
BLAKE2b-256 3405d709b04930649e27212f3b95c327eb4f281465f804022268c31e700167ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bitpacking-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 871ad0d9e004d0bf4950f6d4127c8608154d113d42b70c8d19bccd0fd2511b64
MD5 925cb922d7aea4aaa43b616634ab141d
BLAKE2b-256 ad52ea7ed34e04b7737e86fceb0b1ae5ca8e0fefdc20eac3f9fde1161d69d756

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