Base36

Base36 - способ кодирования, который применяется для чисел

Автор: ShadEx
Платформы: Windows , Linux

base36.png

Function base36encode(number As Uinteger) As String
     Dim alphabet As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     If number = 0 Then Return "0"
     Dim As String res_b36 = ""
     While number > 0
         res_b36 = Mid(alphabet, number Mod 36 + 1, 1) & res_b36
         number = number \ 36
     Wend
     Return res_b36
End Function

Function base36decode(Byref base36 As String) As Uinteger
    Dim alphabet As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Dim As Uinteger num_b36 = 0
    num_b36 = Instr(1, alphabet, Right(base36, 1)) - 1
    For i As Integer = Len(base36) - 1 To 1 Step -1
         num_b36 = num_b36 + 36 ^ (Len(base36) - i) * (Instr(1, alphabet, Mid(base36, i, 1)) - 1)
    Next i
    Return num_b36
End Function

Dim As Uinteger snum = 125175458
Dim As String sint36 = base36encode(snum)
Print sint36
Print base36decode(sint36)
Sleep