是否有一種簡單的方法在Excel中將數字從基數10轉換爲基數36?我有一個需要轉換的超過2000個數字的列表,因此我無法在其中一個在線轉換器中逐一進行轉換。使用公式將基數10轉換爲基數36使用公式
我在想,即使有一種數學方法,我可以使用一個公式。
是否有一種簡單的方法在Excel中將數字從基數10轉換爲基數36?我有一個需要轉換的超過2000個數字的列表,因此我無法在其中一個在線轉換器中逐一進行轉換。使用公式將基數10轉換爲基數36使用公式
我在想,即使有一種數學方法,我可以使用一個公式。
看一看這樣的:
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, "ABCDEF")
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,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Sub main()
Dim MyNumber As Double
MyNumber = 999999999999999#
MsgBox MyNumber & ": " & ConvertBase10(MyNumber, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
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
雖然此鏈接可能回答問題,但最好在此處包含答案的基本部分並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Korem
感謝您的反饋Korem –