A simple binary arithmetic library using 2's complement
Project description
binary_gurdeep
A simple Python library for binary arithmetic operations using 2's complement representation.
Features
- Binary addition and subtraction using 2's complement (without decimal conversion)
- Binary to decimal conversion
- Decimal to binary conversion
- 2's complement calculation
Installation
pip install binary_gurdeep
Or install from the source:
git clone https://github.com/gurdeep/binary_gurdeep.git
cd binary_gurdeep
pip install -e .
Usage
from binary_gurdeep import binary_addition, binary_subtraction, decimal_to_binary, binary_to_decimal
# Convert decimal to binary
binary_8 = decimal_to_binary(8, 5) # '01000'
binary_neg_8 = decimal_to_binary(-8, 5) # '11000'
# Convert binary to decimal
decimal_8 = binary_to_decimal('01000') # 8
decimal_neg_8 = binary_to_decimal('11000') # -8
# Binary addition
result_add = binary_addition('01010', '00011', 5) # '01101' (10 + 3 = 13)
# Binary subtraction
result_sub = binary_subtraction('01010', '00011', 5) # '00111' (10 - 3 = 7)
Examples
Working with Binary Numbers
from binary_gurdeep import binary_addition, binary_subtraction
# Add two binary numbers (7 + 5)
result = binary_addition('00111', '00101', 5) # '01100' (12 in decimal)
# Subtract binary numbers (7 - 5)
result = binary_subtraction('00111', '00101', 5) # '00010' (2 in decimal)
# Handling negative numbers
neg_five = decimal_to_binary(-5, 5) # '11011'
result = binary_addition('00111', neg_five, 5) # '00010' (7 + (-5) = 2)
License
MIT
Author
Gurdeep Singh Virdee
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
binary_gurdeep-0.1.0.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file binary_gurdeep-0.1.0.tar.gz.
File metadata
- Download URL: binary_gurdeep-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74b584c491f25f71864605a4bbc755afc92dfdbbc6a6fcfa468091c029bb0a5d
|
|
| MD5 |
e8d1eca54dd2ccd0ba01411a6b239fc9
|
|
| BLAKE2b-256 |
cba5b93016efec4c60261cc5316299feaaf253b1aaf3f5420c627f0e9a374ad2
|
File details
Details for the file binary_gurdeep-0.1.0-py3-none-any.whl.
File metadata
- Download URL: binary_gurdeep-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06b5c358d390c8c3002c76eeb3e4b277668aa0b01b3f1781cd94e4120a9d0fa1
|
|
| MD5 |
d663b2f235c322cf883d680002c3f6ca
|
|
| BLAKE2b-256 |
1bc6efff1ddb7b060807ef4926354e72a847d6f5116646d2ad55b2d7034fc360
|