VB如何实现进制转换!高手指点!
发布网友
发布时间:2022-05-21 10:25
我来回答
共1个回答
热心网友
时间:2023-10-23 09:00
从F进制转换为T进制,就是 F -> 10 -> T
Dim st1 As String: Dim st2 As String
Dim temp As Integer, F As Integer, T As Integer
Dim chars(): chars = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
F = 16 '来自16进制
T = 10 '转换为10进制
st1 = "1c3" '设置值
st1 = UCase(st1) '转为大写
For i = Len(st1) To 1 Step -1
If Mid(st1, i, 1) >= "0" And Mid(st1, i, 1) <= "9" Then
temp = temp + (Asc(Mid(st1, i, 1)) - 48) * F ^ (Len(st1) - i)
Else
temp = temp + (Asc(Mid(st1, i, 1)) - 65 + 10) * F ^ (Len(st1) - i)
End If
Next i
'从F转换成10
While temp > 0
q = temp Mod T
st2 = chars(q) & st2
temp = temp \ T
Wend
'从10转换成T
MsgBox st2
'输出结果