Skip to main content

Convx | A conversion tool for binary, hex, decimal.

License Version Python Code Style Build Status

Banner

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.

Release files for convx 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for convx 0.1.4
File Size Uploaded
convx-0.1.4.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for convx 0.1.4
File Interpreter ABI Platform
convx-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / convx-0.1.4.tar.gz

Download URL convx-0.1.4.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
13068d0a66b384db56ecf0307b1aaa7d98c1c3d1b733dbb8a6545ba94a4ba3d9
BLAKE2b-256 checksum
How to use checksums
ae4c3accc35836aa2e844c747f8402e5c241f1d0a10c7a47ad54e536c866e7f9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / convx-0.1.4-py3-none-any.whl

Download URL convx-0.1.4-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
203d17c95be61a0fc527fffad4919eb6f19056a5db308ef9db35e4ca12e09483
BLAKE2b-256 checksum
How to use checksums
13ba53472c479a9e131ccf86976a889091ab558e687aa1b3abe481c58b1b5b59
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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