Skip to main content

n_bit_binary

A small module which defines a class for working with n-bit signed or unsigned integers.
Useful for changing specific bits in an integer as it supports slicing.

Installation

pip install n_bit_binary

Usage

Constructing a Binary Integer

The constructor for NBitInteger takes three arguments:

  • number: an integer which is used to set the initial value of the class.
  • bits: an integer which sets the size of the class in bits
  • signed: (optional) defaults to True, determines whether the represented number is signed.
from n_bit_binary import NBitInteger

# signed
n = NBitInteger(-32, 8)

print(n) # -32
print(n.bits) # 8
print(n.signed) # True
print(n.bit_string()) # 11100000

# unsigned
n = NBitInteger(255, 8, signed=False)

print(n) # 255
print(n.bits) # 8
print(n.signed) # False
print(n.bit_string()) # 11111111

Manipulating a Binary Integer

Each bit can be accessed using an its index, where 0 is the most significant bit.

from n_bit_binary import NBitInteger

n = NBitInteger(1, 8) # signed

print(n) # 1
print(n.bit_string()) # 00000001

n[0] = True
print(n) # -127
print(n.bit_string()) # 10000001

Metadata

Release files for n-bit-binary 0.1.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 n-bit-binary 0.1.1
File Size Uploaded Provenance
n_bit_binary-0.1.1.tar.gz 9.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for n-bit-binary 0.1.1
File Interpreter ABI Platform
n_bit_binary-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / n_bit_binary-0.1.1.tar.gz

Download URL n_bit_binary-0.1.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ceb0642848be5d33a69f4413a2427fdbeb3cf852cbc56b427359d71de4c75b4a
BLAKE2b-256 checksum
How to use checksums
0059fa8a01103acaa7b17563cee2b4d92303cf6c638a31ea33b0e07d4cb12041
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / n_bit_binary-0.1.1-py3-none-any.whl

Download URL n_bit_binary-0.1.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
001bf9e70b2c22498dcdde2e2ac3cf886430114201bca30ce5cf2285f8bd8678
BLAKE2b-256 checksum
How to use checksums
a1a9df5d2afa2240c89f2df92e9447cc166c35ebc957a9abae873167b0bb9aaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Security for n-bit-binary 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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