Skip to main content

No project description provided

Project description

🧮 Decimal to Binary Converter

A simple and educational Python utility that converts a decimal number into its binary representation, while showing the step-by-step division process. Perfect for beginners learning how binary conversion works!


📦 Features

✅ Converts any positive integer to binary ✅ Displays detailed division steps for learning ✅ Handles input validation (no negative numbers) ✅ Lightweight — no external dependencies


🚀 Installation

You can install the package directly from PyPI once published:

pip install decimal-to-binary

🧠 Usage

Import and use it in your Python script:

from decimal_to_binary import print_db

print_db(100)

Example Output

------------------------------------------
Divide by 2 till 0 and note the remainders
------------------------------------------
100 / 2 | 0
50 / 2 | 0
25 / 2 | 1
12 / 2 | 0
6 / 2 | 0
3 / 2 | 1
1 / 2 | 1
<-------   reverse the remainders
0011001   to get the final answer
Decimal: (100) Base = 10 --> Binary: (1100100) Base = 2

📜 Function Details

print_db(num: int) -> str Prints the decimal-to-binary conversion result in a readable format.

get_binary(num: int) -> str Performs the actual conversion using the divide-by-2 method, returning the binary representation as a string.

⚠️ Error Handling

Raises ValueError if a negative number is passed:

print_db(-5)
# ValueError: Must Be Positive

🧰 Example CLI Run

If run as a script:

python main.py

Output:

Decimal: (100) Base = 10 --> Binary: (1100100) Base = 2

👨‍💻 Author

Shahaan Bharucha GitHub

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

learn_bin-0.3.3.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

learn_bin-0.3.3-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file learn_bin-0.3.3.tar.gz.

File metadata

  • Download URL: learn_bin-0.3.3.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for learn_bin-0.3.3.tar.gz
Algorithm Hash digest
SHA256 af5ca1df922cce215acff42d96940db7552fa43a21d097912a8d69c4e965000e
MD5 a0eb65b5e563fa01c134367fe05bec72
BLAKE2b-256 ed20996bf5a60b908ba77a1e1f57f99e784c05b6b7f5a4c39b46a0d153440e99

See more details on using hashes here.

File details

Details for the file learn_bin-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: learn_bin-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for learn_bin-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 553975fd693e1932836c93e9b5355c828958137975eb814b85f985ec7ace0808
MD5 c2d4bb1f9ca7066cf502d82739dc88f0
BLAKE2b-256 a03c9e7ccfbd06d1e7c7b805a604bd080e7934dc89c5eb0ea8e776636c003627

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page