Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (80 sloc) 2.81 KB


numconv is a library that converts strings to numbers and numbers to strings using default or user supplied encoding alphabets, written by Gustavo Picón and licensed under the Apache License 2.0.


numconv has been tested in Python 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, PyPy 1.4 and Jython 2.5. Other versions may work but are not supported.

You have several ways to install numconv. If you're not sure, just use pip

pip (or easy_install)

You can install the release versions from numconv's PyPI page using pip:

pip install numconv

or if for some reason you can't use pip, you can try easy_install:

easy_install --always-unzip numconv

Download a release from the numconv download page and unpack it, then run:

python install


.. module:: numconv

.. autoclass:: NumConv

   .. automethod:: int2str

      **Examples** (taken from :file:``):

        3735928559 to hexadecimal::

            >> NumConv(16).int2str(3735928559)

        19284 to binary::

            >> NumConv(2).int2str(19284)

        37 to base 4 using a custom dictionary::

            >> NumConv(4, 'rofl').int2str(37)

        Very large number to :data:`~numconv.BASE85`::

            >> NumConv(85).int2str(2693233728041137)

   .. automethod:: str2int

      **Examples** (taken from :file:``):

        Hexadecimal 'DEADBEEF' to integer::

           >> NumConv(16).str2int('DEADBEEF')

        Binary '100101101010100' to integer::

            >> NumConv(2).str2int('100101101010100')

        Base 4 with custom encoding 'foo' to integer::

            >> NumConv(4, 'rofl').str2int('foo')

        :data:`~numconv.BASE85` '~123AFz@' to integer::

            >> NumConv(85).str2int('~123AFz@')

.. data:: BASE85

   Alphabet defined in section 4 of :rfc:`1924`. Supposed to be a joke
   (it is an April's fools RFC after all), but is quite useful because
   it can be used as a base for the most common numeric conversions.

.. data:: BASE16

   Alphabets defined in :rfc:`4648`. Not really for common numeric
   conversion use.

.. data:: BASE62

   Useful for URL shorteners.

.. autofunction:: int2str

.. autofunction:: str2int

Indices and tables