Skip to main content

Better bit manipulation that allows indexing, and automatic bit flags.

Project description

Color Guard provides simple bit manipulation and bit flags in Python. Everything is built on the int type so no number functionality is lost, while making it possible to index and slice binary numbers like strings.

Basic usage:

>>> num = Bits(20)
>>> num
>>> num * 3
>>> num[:4]
>>> num.bit_length()
>>> num.join(0b101)

Color Guard also supports conversion to and from other Python data types.

>>> Bits.from_binary("111101001101")
>>> Bits.from_hex("abc123")
>>> Bits.from_bytes(b"abc")

>>> bytes(Bits(367))
>>> int(Bits(0b1011010))
>>> list(Bits(367))
[1, 0, 1, 1, 0, 1, 1, 1, 1]


  • Indexing and slicing of binary numbers like strings

  • Conversion between several Python data types

  • All builtin math operations including bit manipulation and comparison

  • Padded binary numbers that maintain bit length

  • Custom, easy-to-use bit flags
    • Bit field loading from bytes or stream

    • Custom data descriptors for fields

    • Field editing & conversion to bytes

For further documentation, visit

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

colorguard-0.4.tar.gz (7.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page