This Python script allows you to convert numbers between different bases, including bases with decimal points. It provides a user-friendly interface for entering the number, the base to convert from, and the base to convert to. The script also includes checks for input validity and ensures the bases are "friends" for certain conversions.
- Python 3.x
- Clone the repository or download the script file.
- Open a terminal or command prompt and navigate to the directory where the script is located.
- Run the script by executing the following command:
python base_converter.py
- Follow the on-screen instructions to enter the number, the base to convert from (FromB), and the base to convert to (ToB).
- The script will perform the conversion and display the result.
make_int(char)
: Converts a character 'A' to 'F' to its corresponding integer value from 10 to 15. Returns False for invalid characters.make_num(char)
: Converts an integer value from 10 to 15 to its corresponding character 'A' to 'F'. Returns False for invalid integers.if_Friend(Fb, Tb)
: Checks if two bases, Fb and Tb, are "friends" (one can be obtained by raising the other to a power between 1 and 8).This_regal(num, B)
: Checks if a given numbernum
is valid in a given baseB
.To_B10(num, Fb, Tb)
: Converts a numbernum
from base Fb to base 10 or from a base with a decimal point to base 10.From_B10(numS, Fb, Tb)
: Converts a numbernumS
from base 10 to base Tb.
Here are some example conversions that you can perform with this script:
- Convert a number from base 2 to base 10:
101012 = 2110
- Convert a number from base 10 to base 16:
4210 = 2A16
- Convert a number from base 16 to base 8:
2A16 = 528
- Convert a number from base 8 to base 5:
1238 = 4435
Enter a num: 1010
From B-> 2
To B-> 10
(1010)2 = (10)10
- The script supports bases from 2 to 16.
- If the entered number is not valid for the specified base, the script will display an error message.
This project is licensed under the MIT License.
- This script was inspired by the need to convert numbers between different bases.
- The concept of "friends" bases was introduced to enhance the conversion capabilities.
- Special thanks to OpenAI for providing the GPT-3.5 model that assisted in generating this README.