Skip to main content

Python Bit Fields provides simple bit manipulation and bit field construction 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
Bits(0b10100)
>>> num * 3
Bits(0b111100)
>>> num[:4]
Bits(0b1010)
>>> num.bit_length()
5
>>> num.join(0b101)
Bits(0b10100101)

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

>>> Bits.from_binary("111101001101")
Bits(0b111101001101)
>>> Bits.from_hex("abc123")
Bits(0b101010111100000100100011)
>>> Bits.from_bytes(b"abc")
Bits(0b11000010110001001100011)

>>> bytes(Bits(367))
b'\x01o'
>>> int(Bits(0b1011010))
90
>>> list(Bits(367))
[1, 0, 1, 1, 0, 1, 1, 1, 1]

Features

  • 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

  • Bit Field Construction
    • Bit field loading from bytes or stream

    • Custom data descriptors for fields

    • Field editing & conversion to bytes

Metadata

Release files for bitfields 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitfields 0.1
File Size Uploaded
bitfields-0.1.tar.gz 7.2 kB Details

Release files / bitfields-0.1.tar.gz

Download URL bitfields-0.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e7f88deff50ff92d840dcde8c9ab7074e9933e425261006d97f9aee9424701da
BLAKE2b-256 checksum
How to use checksums
aabdc8530f2111c9c945258c1b9644e50471fa04472364cd2ea2398de0567dac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page