convert alphanumeric to numeric python

Solutions on MaxInterview for convert alphanumeric to numeric python by the best coders in the world

showing results for - "convert alphanumeric to numeric python"
Gabriele
15 Nov 2017
1chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" #these are the digits you will use for conversion back and forth
2charsLen = len(chars)
3
4def numberToStr(num):
5  s = ""
6  while num:
7    s = chars[num % charsLen] + s
8    num //= charsLen
9
10  return(s)
11
12def strToNumber(numStr):
13  num = 0
14  for i, c in enumerate(reversed(numStr)):
15    num += chars.index(c) * (charsLen ** i)
16
17  return(num)