重点是要学会如何利用按权展开式求和,算法了解了,代码就不难了。
Dim a As String, aa As Integer, b As String, bb As Integer, c As Integer
aa = InputBox("输入的是几进制数?")
aa = Trim(aa)
a = InputBox("数是多少?")
a = Trim(a)
For i = 1 To Len(a)
b = Mid(a, i, 1)
If (b > 9) Then
bb = 10 + b - Asc("A")
Else
bb = Val(b)
End If
c = c + bb * aa ^ (Len(a) - i)
Next i
MsgBox "结果是:" & c