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

Your Name 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.2.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.2-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: learn_bin-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 0fd49cd3238a6a3b98fec507ba9a6d27a4f06b3b930d778a064ab9b455b343ec
MD5 9c5556a5e0512854df912672eca19e82
BLAKE2b-256 3915f32f0b4740284570fc25660ef44ecc12a47cfe7dc3fc22ab7f753c44ece3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: learn_bin-0.3.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eed13f2e60d1466d7c97bf07300cd6aeb23a1c5e3446cc35d504d9a27617e559
MD5 99bf33944b3fd73caf5200c6d63dd044
BLAKE2b-256 5f434dbe8d8e1d4a766a0d78cf64bb3293c3b3e6b2015780d0fa1c92087837a9

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