diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2007-05-18 16:44:43 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2007-05-18 16:44:43 +0000 |
commit | 0683bce893de37d134fe94cb6a19bc90c3ab26e7 (patch) | |
tree | fc931a36f21e79abdeb8aea1c02798bcec1402ef /numpy/f2py/lib/nary.py | |
parent | b3caec68294618d217bdb26872b3c9d235c6ade6 (diff) | |
download | numpy-0683bce893de37d134fe94cb6a19bc90c3ab26e7.tar.gz |
g3 f2py: impl. compiling Fortran codes online (function numpy.f2py.lib.compile), clean up testing.
Diffstat (limited to 'numpy/f2py/lib/nary.py')
-rw-r--r-- | numpy/f2py/lib/nary.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/f2py/lib/nary.py b/numpy/f2py/lib/nary.py new file mode 100644 index 000000000..948672b8c --- /dev/null +++ b/numpy/f2py/lib/nary.py @@ -0,0 +1,32 @@ +""" +nary - convert integer to a number with an arbitrary base. +""" + +__all__ = ['nary'] + +_alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +def _getalpha(r): + if r>=len(_alphabet): + return '_'+nary(r-len(_alphabet),len(_alphabet)) + return _alphabet[r] + +def nary(number, base=64): + """ + Return string representation of a number with a given base. + """ + if isinstance(number, str): + number = eval(number) + n = number + s = '' + while n: + n1 = n // base + r = n - n1*base + n = n1 + s = _getalpha(r) + s + return s + +def encode(string): + import md5 + return nary('0x'+md5.new(string).hexdigest()) + +#print nary(12345124254252525522512324,64) |