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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af5ca1df922cce215acff42d96940db7552fa43a21d097912a8d69c4e965000e
|
|
| MD5 |
a0eb65b5e563fa01c134367fe05bec72
|
|
| BLAKE2b-256 |
ed20996bf5a60b908ba77a1e1f57f99e784c05b6b7f5a4c39b46a0d153440e99
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
553975fd693e1932836c93e9b5355c828958137975eb814b85f985ec7ace0808
|
|
| MD5 |
c2d4bb1f9ca7066cf502d82739dc88f0
|
|
| BLAKE2b-256 |
a03c9e7ccfbd06d1e7c7b805a604bd080e7934dc89c5eb0ea8e776636c003627
|