Skip to content

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.

License

Notifications You must be signed in to change notification settings

OrelAshush123/Number-Base-Converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Number Base Converter

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.

Prerequisites

  • Python 3.x

How to Use

  1. Clone the repository or download the script file.
  2. Open a terminal or command prompt and navigate to the directory where the script is located.
  3. Run the script by executing the following command:
    python base_converter.py
  4. Follow the on-screen instructions to enter the number, the base to convert from (FromB), and the base to convert to (ToB).
  5. The script will perform the conversion and display the result.

Functionality

  • 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 number num is valid in a given base B.
  • To_B10(num, Fb, Tb): Converts a number num from base Fb to base 10 or from a base with a decimal point to base 10.
  • From_B10(numS, Fb, Tb): Converts a number numS from base 10 to base Tb.

Examples

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

input-output example (how to use)

Enter a num: 1010 From B-> 2 To B-> 10 (1010)2 = (10)10

Notes

  • 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.

License

This project is licensed under the MIT License.

Acknowledgments

  • 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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages