Skip to content

Instantly share code, notes, and snippets.

@debbbbie
Created January 16, 2014 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debbbbie/8450662 to your computer and use it in GitHub Desktop.
Save debbbbie/8450662 to your computer and use it in GitHub Desktop.
64进制互转
#coding=gbk
digit64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'
def int_to_str64( x ):
try:
x=int(x)
except:
x=0
if x<0:
x=-x
if x==0:
return "0"
s=""
while x>64:
x1= x % 64
s = digit64[x1]+s
x = x // 64
if x>0:
s = digit64[x]+s
return s
def str64_to_int( s ):
x = 0
s = str(s).strip()
if s=="":
return x
for y in s:
k = digit64.find(y)
if k>=0:
x=x*64+k
return x
x = 58
s = int_to_str64(x)
y = str64_to_int( s)
print( x , s , y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment