Skip to content

Instantly share code, notes, and snippets.

@aniruddha-adhikary
Last active January 16, 2016 15:17
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 aniruddha-adhikary/0bbebde1071df90e8c54 to your computer and use it in GitHub Desktop.
Save aniruddha-adhikary/0bbebde1071df90e8c54 to your computer and use it in GitHub Desktop.
def decimal_to_base_n(number, base, \
symbolarray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']):
if(base > len(symbolarray)):
raise ValueError
result = ''
number = int(number)
i = 0
print "%d | %d" % (base, number)
if(number == 0):
print 0
exit()
while(number != 0):
remains = number % base
number = number / base
i += 1
print "%s%d | %d - %d" % (" "*i, base, number, remains)
result += symbolarray[remains]
print result[::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment