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 again

tabo / numconv

Python library to convert strings to numbers and numbers to strings. Docs: http://docs.tabo.pe/numconv/tip/

Clone this repository (size: 168.1 KB): HTTPS / SSH
hg clone https://bitbucket.org/tabo/numconv
hg clone ssh://hg@bitbucket.org/tabo/numconv

numconv / docs / index.rst

commit
a507bcdecc11
parent
6b6d6c1b9e5c
branch
default

docs

1
a507bcdecc11
numconv
2
a507bcdecc11
=======
3
0928d42622f4
4
a507bcdecc11
:synopsys: Convert strings to numbers and numbers to strings.
5
a507bcdecc11
:copyright: 2008-2009 by Gustavo Picon
6
a507bcdecc11
:license: Apache License 2.0
7
a507bcdecc11
:version: 2.1a
8
a507bcdecc11
:url: http://code.tabo.pe/numconv/
9
a507bcdecc11
:documentation:
10
a507bcdecc11
   `numconv-docs
11
a507bcdecc11
   <http://docs.tabo.pe/numconv/2.0/>`_
12
a507bcdecc11
:examples:
13
a507bcdecc11
   `numconv-tests
14
a507bcdecc11
   <http://code.tabo.pe/numconv/src/2.0/tests.py>`_
15
0928d42622f4
16
a507bcdecc11
:mod:`numconv` converts a string into a number and a number into a string
17
a507bcdecc11
using default or user supplied encoding alphabets.
18
7c4b7067b2fc
19
7c4b7067b2fc
20
a507bcdecc11
.. module:: numconv
21
7c4b7067b2fc
22
a507bcdecc11
.. autoclass:: NumConv
23
a507bcdecc11
   :show-inheritance:
24
0928d42622f4
25
a507bcdecc11
   .. automethod:: int2str
26
a507bcdecc11
27
a507bcdecc11
      **Examples** (taken from :file:`tests.py`):
28
a507bcdecc11
29
a507bcdecc11
        3735928559 to hexadecimal::
30
a507bcdecc11
31
a507bcdecc11
            >> NumConv(16).int2str(3735928559)
32
a507bcdecc11
            'DEADBEEF'
33
a507bcdecc11
34
a507bcdecc11
        19284 to binary::
35
a507bcdecc11
36
a507bcdecc11
            >> NumConv(2).int2str(19284)
37
a507bcdecc11
            '100101101010100'
38
a507bcdecc11
39
a507bcdecc11
        37 to base 4 using a custom dictionary::
40
a507bcdecc11
41
a507bcdecc11
            >> NumConv(4, 'rofl').int2str(37)
42
a507bcdecc11
            'foo'
43
a507bcdecc11
44
a507bcdecc11
        Very large number to :data:`~numconv.BASE85`::
45
a507bcdecc11
46
a507bcdecc11
            >> NumConv(85).int2str(2693233728041137)
47
a507bcdecc11
            '~123AFz@'
48
a507bcdecc11
49
a507bcdecc11
   .. automethod:: str2int
50
a507bcdecc11
51
a507bcdecc11
      **Examples** (taken from :file:`tests.py`):
52
a507bcdecc11
53
a507bcdecc11
        Hexadecimal 'DEADBEEF' to integer::
54
a507bcdecc11
55
a507bcdecc11
           >> NumConv(16).str2int('DEADBEEF')
56
a507bcdecc11
           3735928559
57
a507bcdecc11
58
a507bcdecc11
        Binary '100101101010100' to integer::
59
a507bcdecc11
60
a507bcdecc11
            >> NumConv(2).str2int('100101101010100')
61
a507bcdecc11
            19284
62
a507bcdecc11
63
a507bcdecc11
        Base 4 with custom encoding 'foo' to integer::
64
a507bcdecc11
65
a507bcdecc11
            >> NumConv(4, 'rofl').str2int('foo')
66
a507bcdecc11
            37
67
a507bcdecc11
68
a507bcdecc11
        :data:`~numconv.BASE85` '~123AFz@' to integer::
69
a507bcdecc11
70
a507bcdecc11
            >> NumConv(85).str2int('~123AFz@')
71
a507bcdecc11
            2693233728041137
72
a507bcdecc11
73
a507bcdecc11
74
a507bcdecc11
.. data:: BASE85
75
a507bcdecc11
76
a507bcdecc11
   Alphabet defined in section 4 of :rfc:`1924`. Supposed to be a joke
77
a507bcdecc11
   (it is an April's fools RFC after all), but is quite useful because
78
a507bcdecc11
   it can be used as a base for the most common numeric conversions.
79
a507bcdecc11
80
a507bcdecc11
.. data:: BASE16
81
a507bcdecc11
          BASE32
82
a507bcdecc11
          BASE32HEX
83
a507bcdecc11
          BASE64
84
a507bcdecc11
          BASE64URL
85
a507bcdecc11
86
a507bcdecc11
   Alphabets defined in :rfc:`4648`. Not really for common numeric
87
a507bcdecc11
   conversion use.
88
a507bcdecc11
89
a507bcdecc11
.. data:: BASE62
90
a507bcdecc11
91
a507bcdecc11
   Useful for URL shorteners.
92
a507bcdecc11
93
a507bcdecc11
94
a507bcdecc11
functions
95
a507bcdecc11
---------
96
a507bcdecc11
97
a507bcdecc11
.. autofunction:: int2str
98
a507bcdecc11
99
a507bcdecc11
.. autofunction:: str2int
100
0928d42622f4
101
0928d42622f4
102
0928d42622f4
103
0928d42622f4
Indices and tables
104
0928d42622f4
==================
105
0928d42622f4
106
0928d42622f4
* :ref:`genindex`
107
0928d42622f4
* :ref:`modindex`
108
0928d42622f4
* :ref:`search`
109
0928d42622f4