Package: number-conversions
This package allows you to convert a number between any of the 82
standard bases described byWikipediaandhere. It provides both commandline options
and in code options to convert.The chosen 360 characters are availableherealong with their unicode indexes.Use in command lineUse in python codeIn Command LineThere are several ways to use from command line withpython-mconvert_numbers.*command.a) convert_numbers.convertThis is the simplest one time conversion command. It takes two
positional arguments and one optional.a.number: The number to be converted.b.new_base: Base to convert the number two.c.current_base: The base of the number currently. This is an
optional argument. If it’s not included the base is assumed to be base
10/Decimal. The marker is--current_baseor-cb.python -m convert_numbers.convert number new_base --current_base
python -m convert_numbers.convert number new_base -cb

python -m convert_numbers.convert 12 2 -cb 10b) convert_numbers.loopThis converts the input and waits for more input to convert until it’s
quit. The user types in 3 numbers separated by a space.number_to_convert base_to_convert_to current_baseIf current_base is not provided base 10 is assumed. Runs until user
types ‘q’. For help type ‘h’.python -m convert_numbers.loop
Enter 'number new_base current_base': number new_base current_base*

Enter 'number new_base current_base': 12 2 10*
'12' in Decimal (base 10) to Binary (base 2) = '1100'
Enter 'number new_base current_base': qc) convert_numbers.tableTakes a list from input and converts it to the new base and returns a
nice table as output. Takes 5 arguments, 2 positional and 3 optional.a)numbers: A list of numbers to convert separated by comma, no
spaces. These numbers must be in the same base.b)new_base: Base to convert all the numbers to.c)current_base: Current base of all the numbers. This is an
optional argument. When ignored, the base is assumed to be 10.The
marker is--current_baseor-cb.d)file: The file to write the output to. This is an optional
argument. When ignored, the output is the console. The marker is--fileor-fe.in_file: The file to be treated as input. This is an optional
argument. If it is includednumbersis ignored. So it can be left
as 0 or anything, but never blank :( The format for in file is
comma-separated numbers (new lines are treated as commas). The marker
is--in_fileor-if.python -m convert_numbers.table 12,13,14 2 -cb=16


Base 16 to base 2
----------------------------
|  Hexadecimal  |  Binary  |
----------------------------
|       12      |  10010   |
|       13      |  10011   |
|       14      |  10100   |
----------------------------An example of input file is foundhere.d) convert_numbers.fileThis takes input completely from a file and outputs to another file. In
the file, the first line is the list of comma-separated numbers to
convert, the second is the new base, while the third is the current
base, if any otherwise it’s base 10. Example input isherepython -m convert_numbers.file input_file.txt output_file.txt

Written to 'out_file.txt'Writes a csv like file, two columns old number, new number. The first
two rows are informational.In python codeSeveral functions are described by the package. They areconvert_number,convert_from_base_10,convert_float_from_base_10,convert_to_base_10andconvert_float_to_base_10. To check user input refer tothis
sectionMain FunctionsThese, only one, can be used in isolation to convert a number from any
base to any other base.1. convert_numberUsed to convert a number between bases. Takes 3 arguments;a)number: string = The number to be converted in string form.b)base_from: integer = The base ofnumber.c)base_to: integer = The base to convert to. Return a string with
the new converted numberUsagefromconversionsimportconvert_numberconvert_number('12',10,2)# return '1100'Helper FunctionsThey are found inconversions.convertmodule. These are used to
perform one simple action. These functions can be divided by four
categories;1. Category 1: Converts a number frombase 10toany other
base.2. Category 2: Converts a number fromany basetobase 10.3. Category 3: Converts a number that is a whole number. These
functions typically belong to either of the categories above.4. Category 4: Converts a number that is a floating number. These
functions typically belong to either of the categories above.This means that a function can be from two points of view; one, does
it convert awhole number or a floating number? two does it
convertfrom or to base 10? All functions typically belong to two
categories.1. convert_from_base_10Converts a whole number in base 10 to any base. This function is
category 1 and category 3. Takes 2 arguments;a)decimal: integer = This is the whole number to be converted.b)new_base: integer = The base to convert to.Return a list['converted_digit', new_base]Usagefromconversions.convertimportconvert_from_base_10result=convert_from_base_10(12,2)# returns ['1100', 2]2. convert_float_from_base_10Converts a floating number in base 10 to any base. This function is
category 1 and category 4. It returns the maximum possible number
decimal points. However in case of recurring decimal points, the
maximum points is 15. The number has to be less than 1.Returns a list['converted_digit', new_base]Takes two arguments:a)floating_decimal: float = A number less than 1 but greater than
0, to be converted.b)new_base: integer = The base to convert the number to.Usagefromconversions.convertimportconvert_float_from_base_10result=convert_float_from_base_10(0.25,2)# ['0.01', 2]3. convert_to_base_10Converts a whole number from any base back to base 10. This function
is category 2 and category 3. Returns an integer that is base 10.
Takes two arguments:a)number: string = The number to be converted in string form.b)current_base: integer = The base of the number currently.Usagefromconversions.convertimportconvert_to_base_10result=convert_to_base_10('1001',2)# returns 94. convert_float_to_base_10Converts a floating number from any base back to base 10. This
function is category 2 and category 4. It returns a float. Takes two
arguments:a)number: string = The string representation of the number to
convert. It should be less than 1 but greater than 0.b)current_base: integer = The base of the number currently.Usagefromconversions.convertimportconvert_float_to_base_10result=convert_float_to_base_10('0.2',16)# returns 0.125Utility functionsSince none of these functions care whether the user input is factually
correct, e.g., G4 cannot be base 16 or 63 is not a standard base or
whether a character is used to represent these numbers, usen_utilsto check. It provides the following functions:a.n_utils.ensure_base_is_standard- Takes the base, in integer
form, and checks whether it’s one of the 82 standard ones. ReturnsTrueorFalse.b.n_utils.base_limits- Takes the number, in string form, and the
base provided, in integer form and checks whether its factually
correct. ReturnsTrueorFalse.To check the name of a base given the base, usen_utils.base_findwhich takes the base as argument and returns a string of the name of the
base.fromn_utilsimportbase_find,ensure_base_is_standard,base_limitsensure_base_is_standard(63)# Falseensure_base_is_standard(64)# Truebase_limits('G4',16)# Falsebase_limits('G4',20)# Truebase_find(2)# Binarybase_find(10)# Decimal