题型:综合题 题类:常考题 难易度:困难
高中信息技术综合库-VB程序的创建练习2
转换方法:先从右往左将二进制数分割成 4 位一组,若最左边的一组不足4位,则用 0 将高位补足,然后将每 4 位二进制数转换为 1 位十六进制数。
Private Sub Convert_Click()
Dim a(1 To 100) As Integer, temp As Integer
Dim s As String, res As String, n As Integer, r As Integer
res = ""
s=TextB.text
n = Len(s)
For i = 1 To n
a(i) = Val(Mid(s, i, 1))
Next i
t = n \ 4
r = ①
temp = 0
For i = 1 To r ‘将最高的r位转换为十六进制
②
Next i
If temp > 9 Then
res = Chr(temp + 55)
ElseIf temp > 0 Then
res = CStr(temp) ‘Cstr()函数用于将数值转换为字符串,同时删除前导空格
End If
For i = 1 To t ‘将t组4位二进制转换为十六进制
Temp=0
For j=1 to 4
temp = temp+a(j+r+4*(i-1))*2^(4-j)
Next j
If temp > 9 Then
res = res + Chr(temp + 55)
Else
res = res + CStr(temp)
End If
Next i
TextH.Text = res
End Sub
第①处代码为
第②处代码为
试题篮