把一个16进制数转换成一个10进制数。
答案:2 悬赏:70 手机版
解决时间 2021-05-11 15:44
- 提问者网友:临风不自傲
- 2021-05-11 08:18
vb作业,谢谢~~~~~~~~~
最佳答案
- 五星知识达人网友:刀戟声无边
- 2021-05-11 08:45
Function hex2dec(h As String) As Long
Dim n As Long, t As String
For i = 1 To Len(h)
t = UCase(Mid(h, Len(h) - i + 1, 1))
If t > "A" Then
n = n * 16 + 10 + Asc(t) - Asc("A")
Else
n = n * 16 + Asc(t) - Asc("0")
End If
Next i
hex2dec = n
End Function
Private Sub Command1_Click()
Print hex2dec("ffff")
End Sub
Dim n As Long, t As String
For i = 1 To Len(h)
t = UCase(Mid(h, Len(h) - i + 1, 1))
If t > "A" Then
n = n * 16 + 10 + Asc(t) - Asc("A")
Else
n = n * 16 + Asc(t) - Asc("0")
End If
Next i
hex2dec = n
End Function
Private Sub Command1_Click()
Print hex2dec("ffff")
End Sub
全部回答
- 1楼网友:忘川信使
- 2021-05-11 10:09
Private Sub Command1_Click()
Text2.Text = ""
ST Text1.Text
End Sub
Private Sub ST(strz As String)
Dim s As Integer, a As Integer, i As Integer, strg As String 'strz是你输入的16进制数
For i = Len(strz) To 1 Step -1
strg = Mid(strz, i, 1)
If Asc(strg) >= 65 And Asc(strg) <= 70 Then
a = Asc(strg) - 55
ElseIf Asc(strg) >= 97 Then
a = Asc(strg) - 87
Else
a = strg
End If
s = s + a * 16 ^ (i - 1)
Next i
Text2 = Text2 & s
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 65 Or KeyAscii > 70) And (KeyAscii < 97 Or KeyAscii > 102) And (KeyAscii < 48 Or KeyAscii > 57) Then
i = MsgBox("请输入16进制数")
End If
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯