What does this mean for you programmers who write in python? Well it means that we will no longer have to use and import multiple libraries to convert bases.
As most people have noticed pythons
int() only supports one way base conversions.
int('lol',36) // => 28101. Pythons
format() also only supports conversion the other way up to base 16. This library was created to help those python programmers by providing a bases conversion system that works both ways, can use customized conversions and supports from base 2 all the way up to base 64 all in one library.
I hope everyone enjoys this library especially now that it can be installed with pip.
If you feel like using it then give it a spin.
pip install bases.py
from bases import Bases bases = Bases() bases.toBase16(200) // => 'c8' bases.toBase62(99999) // => 'q0T' bases.toAlphabet(300, 'aAbBcC') // => 'Abba' bases.fromBase16('c8') // => 200 bases.fromBase62('q0T') // => 99999 bases.fromAlphabet('Abba', 'aAbBcC') // => 300
Going from numbers to strings:
toAlphabet(num, alphabet): returns a string representation of the given number for the given alphabet, where the alphabet is an arbitrary string of characters. (See known alphabets below for examples.)
toBase(num, base): convenience helper for known bases (see below).
toBaseX(num): convenience helpers for known bases (see below), e.g.
Going from strings to numbers:
fromAlphabet(str, alphabet): returns an integer representation of the given string for the given alphabet.
fromBase(num, base): convenience helper for known bases.
fromBaseX(str): convenience helpers for known bases.
|Base-32 (from Douglas Crockford)||
|Base-58 (from Flickr)||
|Base-64 (as standardized)||
Base-64 warning: besides there being several different standards, padding isn't currently added and line lengths aren't tracked. Not recommended for use with APIs that expect formal base-64 strings!
You can also find the source code for this project at Github