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 decimals, and converting between decimal and binary using two's compliment.
Installation
To install Convx you can use pip install
.
pip install convx
Usage
Simply import Conx using import
. Then use as seen in the example of a cli program 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]) == "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.")
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.0.4.tar.gz
(9.9 kB
view hashes)
Built Distribution
convx-0.0.4-py3-none-any.whl
(6.2 kB
view hashes)