A package for quickly converting binary, hex and decimal to one another.
Project description
Convx | A conversion tool for binary, hex, decimal.
This tool is created for a school lesson regarding Information Representation and conversion between binary, decimal and hex.
Further, this tool has the additional functionality of:
- Adding and subtracting binary.
- Converting between decimal and binary using two's compliment.
- Converting between decimal and BCD.
Installation
To install Convx you can use pip install
.
pip install convx
Usage
Simply import Conx using import
. The functions available are listed below.
# Decimal to Binary
decimalToBinary(x: int)
# Binary to Decimal
binaryToDecimal(x: str)
# Decimal to Hex
decimalToHex(x: str)
# Binary to Hex
binaryToHex(x: str)
# Decimal to BCD
decimalToBCD(x: int)
# BCD to Decimal
bcdToDecimal(x: str)
# Adding Binary
addBinary(x: str, y: str)
# Subtracting Binary
subBinary(x:str , y: str)
# Binary to Denary using two's compliment
twoBinaryToDenary(x: str)
# Denary to Binary using two's compliment
twoDenaryToBinary(x: int)
An example usage of Convx for a cli is given below :
from convx import *
try:
if str(sys.argv[1]) == "dtb":
binary = decimalToBinary(int(sys.argv[2]))
result = f"[*] {int(sys.argv[2])} to binary = {binary}"
print(result)
elif str(sys.argv[1]) == "btd":
decimal = binaryToDecimal(str(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to decimal = {decimal}"
print(result)
elif str(sys.argv[1]) == "dth":
hex = decimalToHex(str(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to hex = {hex}"
print(result)
elif str(sys.argv[1]) == "bth":
hex = binaryToHex(str(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to hex = {hex}"
print(result)
elif str(sys.argv[1]) == "dtbcd":
bcd = decimalToBCD(str(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to BCD = {bcd}"
print(result)
elif str(sys.argv[1]) == "bcdtd":
decimal = bcdToDecimal(str(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to BCD = {decimal}"
print(result)
elif str(sys.argv[1]) == "add":
binary = addBinary(str(sys.argv[2]), str(sys.argv[3]))
result = f"[x] {str(sys.argv[2])} + {str(sys.argv[3])} = {binary}"
print(result)
elif str(sys.argv[1]) == "sub":
binary = subBinary(str(sys.argv[2]), str(sys.argv[3]))
result = f"[x] {str(sys.argv[2])} - {str(sys.argv[3])} = {binary}"
print(result)
elif str(sys.argv[1]) == "2btd":
decimal = twoBinaryToDenary(str(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to decimal = {decimal}"
print(result)
elif str(sys.argv[1]) == "2dtb":
binary = twoDenaryToBinary(int(sys.argv[2]))
result = f"[*] {str(sys.argv[2])} to binary = {binary}"
print(result)
elif str(sys.argv[1]) == "help":
print(help())
except IndexError:
print("[*] No arguments inputed. Exiting.")
Update Log
0.1.3
- Fixed a bug with the banner.
0.1.2
- Added usage in README.
- Updated example cli code.
0.1.1
- Added decimal to BCD and BCD to decimal.
- Added pytest for decimal to BCD and BCD to decimal.
- Added 'help' text at banner information.
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
convx-0.1.4.tar.gz
(12.4 kB
view details)
Built Distribution
convx-0.1.4-py3-none-any.whl
(7.2 kB
view details)
File details
Details for the file convx-0.1.4.tar.gz
.
File metadata
- Download URL: convx-0.1.4.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13068d0a66b384db56ecf0307b1aaa7d98c1c3d1b733dbb8a6545ba94a4ba3d9 |
|
MD5 | 0672c0830a83b0e07712457a84e7cc9d |
|
BLAKE2b-256 | ae4c3accc35836aa2e844c747f8402e5c241f1d0a10c7a47ad54e536c866e7f9 |
File details
Details for the file convx-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: convx-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 203d17c95be61a0fc527fffad4919eb6f19056a5db308ef9db35e4ca12e09483 |
|
MD5 | bcd0928e0084f6f92e01616fcf902ab6 |
|
BLAKE2b-256 | 13ba53472c479a9e131ccf86976a889091ab558e687aa1b3abe481c58b1b5b59 |