有没有一种简单的方法可以在 Excel 中将数字从 Base 10 转换为 Base 36?我有一个需要转换的 2,000 多个数字的列表,因此我无法在其中一个在线转换器中一一进行。
我在想,即使有一种数学方法,我也可以使用公式。
更好的解决方案是使用 BASE 函数
=Base(要转换的数字,base)
例如
=基础(35,36)= Z
=基础(36,36)= 10
看看这个:
http://www.thetropicalevents.com/Xnumbers60/
http://www.thetropicalevents.com/Xnumbers60.htm
[按Korem的要求添加了代码]
或者
Sub main()
Dim base10Number As Double
base10Number = Int(Rnd * 1000)
Debug.Print base10Number, ConvertBase10(base10Number, "0123456789ABCDEF")
End Sub
Public Function ConvertBase10(ByVal d As Double, ByVal sNewBaseDigits As String) As String
Dim S As String, tmp As Double, i As Integer, lastI As Integer
Dim BaseSize As Integer
BaseSize = Len(sNewBaseDigits)
Do While Val(d) <> 0
tmp = d
i = 0
Do While tmp >= BaseSize
i = i + 1
tmp = tmp / BaseSize
Loop
If i <> lastI - 1 And lastI <> 0 Then S = S & String(lastI - i - 1, Left(sNewBaseDigits, 1)) 'get the zero digits inside the number
tmp = Int(tmp) 'truncate decimals
S = S + Mid(sNewBaseDigits, tmp + 1, 1)
d = d - tmp * (BaseSize ^ i)
lastI = i
Loop
S = S & String(i, Left(sNewBaseDigits, 1)) 'get the zero digits at the end of the number
ConvertBase10 = S
End Function
复制自http://www.freevbcode.com/ShowCode.asp?ID=6604
或类似的......
=ConvertBase10(A1,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Sub main()
Dim MyNumber As Double
MyNumber = 999999999999999#
MsgBox MyNumber & ": " & ConvertBase10(MyNumber, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
End Sub
Public Function ConvertBase10(ByVal d As Double, ByVal sNewBaseDigits As String) As String
Dim S As String, tmp As Double, i As Integer, lastI As Integer
Dim BaseSize As Integer
BaseSize = Len(sNewBaseDigits)
Do While Val(d) <> 0
tmp = d
i = 0
Do While tmp >= BaseSize
i = i + 1
tmp = tmp / BaseSize
Loop
If i <> lastI - 1 And lastI <> 0 Then S = S & String(lastI - i - 1, Left(sNewBaseDigits, 1)) 'get the zero digits inside the number
tmp = Int(tmp) 'truncate decimals
S = S + Mid(sNewBaseDigits, tmp + 1, 1)
d = d - tmp * (BaseSize ^ i)
lastI = i
Loop
S = S & String(i, Left(sNewBaseDigits, 1)) 'get the zero digits at the end of the number
ConvertBase10 = S
End Function