This Python program is a command-line tool for converting numbers between binary, octal, hexadecimal, and decimal formats. It provides a menu-driven interface allowing users to set a number and base, and perform conversions. The program uses the colorama
library to enhance terminal output with color and includes error handling for invalid inputs.
- Set a number (or use a random number).
- Set the base for conversions (2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal).
- Convert numbers to binary, octal, hexadecimal, and decimal formats.
- Colorful terminal output using
colorama
. - Robust error handling for user inputs.
-
Clone the Repository:
git clone https://github.com/nishuR31/Number_converter.git cd Number_converter
-
Install Dependencies: Make sure you have Python installed, then install the required packages using pip:
pip install colorama
or
pip install -r requirements.txt
-
Run the Program:
python converter.py
python -u "converter.py"
-
Menu Options:
- 1. Set Number: Enter a number or let the program use a random value.
- 2. Set Base: Enter the base for conversion (2, 8, 10, 16).
- 3. Convert to Binary: Convert the number to binary.
- 4. Convert to Octal: Convert the number to octal.
- 5. Convert to Hexadecimal: Convert the number to hexadecimal.
- 6. Convert to Decimal: Display the decimal value of the number.
- 7. Exit: Exit the program.
-
Example Interaction:
Menu: 1. Set Number 2. Set Base 3. Convert to Binary 4. Convert to Octal 5. Convert to Hexadecimal 6. Convert to Decimal 7. Exit Choose an option: 1 Enter your number or we'll take random: 42 Number set to: 42 Choose an option: 3 Binary value of 42 with base 10 is 0b101010 Choose an option: 7 Exiting the program. Goodbye!
- Invalid inputs for numbers or bases are handled with appropriate error messages.
- Base must be one of the following values: 2, 8, 10, or 16.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to submit issues and pull requests to enhance the functionality or fix bugs.
For questions or suggestions, please contact nishanrajak7679@gmail.com or Github.