Skip to content

Instantly share code, notes, and snippets.

@ohcrider
Last active September 24, 2015 05:23
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 ohcrider/935d8e17eed79fa1ab13 to your computer and use it in GitHub Desktop.
Save ohcrider/935d8e17eed79fa1ab13 to your computer and use it in GitHub Desktop.
python converter 10 to 26
# -*- coding: utf-8 -*-
'''
copyright: (c) 2015 by fewspider(fewspider@gmail.com).
~~~~~~~~~
converter 10 to 26,like:
1 -> A
2 -> B
27 -> AA
~~~~~~~~~
test it:
python base10to26.py 27
'''
import sys
def base10to26(num):
converted_string, modstring = '', ''
currentnum = num
while currentnum:
mod = currentnum % 26
mod = mod if mod != 0 else 26
currentnum = (currentnum - mod) // 26
converted_string = chr(64 + mod) + converted_string
return converted_string
if __name__ == '__main__':
num = int(sys.argv[1])
rs = base10to26(num)
print 'num-----', num
print 'result------', rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment