2013-02-03 36 views
2

是否有一種簡單的方法在Excel中將數字從基數10轉換爲基數36?我有一個需要轉換的超過2000個數字的列表,因此我無法在其中一個在線轉換器中逐一進行轉換。使用公式將基數10轉換爲基數36使用公式

我在想,即使有一種數學方法,我可以使用一個公式。

回答

1

看一看這樣的:

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 

從複製:https://groups.google.com/forum/?fromgroups=#!topic/microsoft.public.excel.worksheet.functions/yY7U_kX_FwU

+1

雖然此鏈接可能回答問題,但最好在此處包含答案的基本部分並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Korem

+0

感謝您的反饋Korem –

2

更好的解決方案將是使用基函數

=基(數轉換,基峯)

例如

=基數(35,36)= Z

=基數(36,36)= 10

+0

第二個答案通常是最好的! – Chris