用VB编写一个将n进制整数转换成十进制数的通用程序!

2022-08-15 社会 27阅读

重点是要学会如何利用按权展开式求和,算法了解了,代码就不难了。


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
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com