Option Explicit
Private Const Chaine = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Function Base10toN(ByVal Valeur As Long, ByVal Base As Long) As String
Dim v As Long, str As String
If (Base < 2) Or (Base > 36) Then Exit Function
Do
v = Valeur Mod Base
Valeur = Int(Valeur / Base)
str = Mid(Chaine, 1 + v, 1) & str
Loop While Valeur > 0
Base10toN = str
End Function
Function BaseNto10(ByVal Valeur As String, ByVal Base As Long) As Long
Dim v As Long, i As Long, j As Long, iVal As Long
If (Base < 2) Or (Base > 36) Then Exit Function
For i = Len(Valeur) To 1 Step -1
v = InStr(1, Chaine, Mid(Valeur, i, 1)) - 1
If v < 0 Or v >= Base Then Exit Function
For j = 1 To Len(Valeur) - i
v = v * Base
Next
iVal = iVal + v
Next i
BaseNto10 = iVal
End Function
|