Skip to content

Base Conversion

Kleb edited this page May 23, 2022 · 7 revisions

The baseconversion module allows for conversion between number bases up to base 64.

baseconversion is a part of the ‘maths’ sub-package.

Back to maths

Simple Base Conversion

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.

Dual Base Conversion

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.

Back to maths

Clone this wiki locally