-
Notifications
You must be signed in to change notification settings - Fork 1
Base Conversion
The baseconversion module allows for conversion between number bases up to base 64.
baseconversion is a part of the ‘maths’ sub-package.
baseconversion.convert_base(num, base, ansBase)
will convert a given number num
in base base
to the base ansBase
. num
must be a string containing only digits that are valid in the given base. base
and ansBase
must be integers between 2 and 128 inclusive, or dual bases as described below.
This part of the module allows for conversion between so-called dual bases, wherein a single digit of the outer base is represented by n digits of an inner base, where n = loginner(outer). For example, 41310 would be represented in dual base 36/6 as 142436/6, where 146 and 246 represent A36 and G36 respectively.
To convert between dual bases, use baseconversion.convert_base
, substituting one of the bases for a string in the form outer/inner
. Standard and dual bases can be used interchangeably in this way.