Bit common types and utilities.
Project description
README.md
bit-common
bit-common
is a Python library that provides types and utilities for working with bits. It allows you to easily convert data to and from bits, making it a handy tool for low-level programming, data analysis, and more.
Installation
You can install bit-common
using pip or poetry.
Using pip
pip install bit-common
Using poetry
poetry add bit-common
Usage
Here are some examples of how you can use bit-common
.
Converting data to bits
from bit.type import int8, UTF8StringWithPrefix
# Converting data to bits
data = int8(3)
bits = data.to_bits()
print(bits) # Output: [1, 1, 0, 0, 0, 0, 0, 0]
# Converting bits to data
bits = [1, 1, 0, 0, 0, 0, 0, 0]
data = int8.from_bits(bits)
print(data) # Output: 3
# Converting string to bits
string = UTF8StringWithPrefix("Hello")
bits = string.to_bits()
print(bits) # Output: [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0]
# Converting bits to string
bits = [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0]
string = UTF8StringWithPrefix.from_bits(bits)
print(string) # Output: "Hello"
License
bit-common
is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bit_common-0.1.9.tar.gz
(9.3 kB
view hashes)
Built Distribution
bit_common-0.1.9-py3-none-any.whl
(12.8 kB
view hashes)
Close
Hashes for bit_common-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc8522009a96b2a4af21fa4e3a11260597d24531ad2049aec09ae2fd90c4b0ae |
|
MD5 | 8cf04e6e1e7b23c22825534f86f0791c |
|
BLAKE2b-256 | 6ec70f4855b4f14751fd50a8a34f34da4210b1a9f8c90d17619fa6e816c8c0c4 |