Gustavo Picon is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | numconv
=======
`numconv <https://tabo.pe/projects/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 <https://tabo.pe>`_ and
licensed under the Apache License 2.0.
Installation
------------
``numconv`` has been tested in Python 2.4, 2.5, 2.6, 2.7, 3.0 and 3.1. Other
versions may work but are not supported.
You have several ways to install ``numconv``. If you're not sure,
`just use pip <http://guide.python-distribute.org/pip.html>`_
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
setup.py
~~~~~~~~
Download a release from the `numconv download page`_ and unpack it, then
run::
python setup.py install
API
---
.. module:: numconv
.. autoclass:: NumConv
.. automethod:: int2str
**Examples** (taken from :file:`tests.py`):
3735928559 to hexadecimal::
>> NumConv(16).int2str(3735928559)
'DEADBEEF'
19284 to binary::
>> NumConv(2).int2str(19284)
'100101101010100'
37 to base 4 using a custom dictionary::
>> NumConv(4, 'rofl').int2str(37)
'foo'
Very large number to :data:`~numconv.BASE85`::
>> NumConv(85).int2str(2693233728041137)
'~123AFz@'
.. automethod:: str2int
**Examples** (taken from :file:`tests.py`):
Hexadecimal 'DEADBEEF' to integer::
>> NumConv(16).str2int('DEADBEEF')
3735928559
Binary '100101101010100' to integer::
>> NumConv(2).str2int('100101101010100')
19284
Base 4 with custom encoding 'foo' to integer::
>> NumConv(4, 'rofl').str2int('foo')
37
:data:`~numconv.BASE85` '~123AFz@' to integer::
>> NumConv(85).str2int('~123AFz@')
2693233728041137
.. 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
BASE32
BASE32HEX
BASE64
BASE64URL
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
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. _`numconv's PyPI page`:
http://pypi.python.org/pypi/numconv
.. _`numconv download page`:
http://code.tabo.pe/numconv/downloads/
|