当前位置: 高中信息技术 / 综合题
  • 1. (2020高二下·温州期中) 编写VB程序,实现如下功能:在文本框Text1中输入二进制数,单击“转换”命令按钮Command1,在文本框Text2中输出对应的十六进制数。程序运行界面如图所示,请回答下列问题:

    1. (1) 如果输入的二进制数为“1101010”,则得到的结果为
    2. (2) 实现上述功能的 VB 程序如下,请在划线处填入合适代码。

      ‘函数 bw 功能:若二进制位数不足,通过在前面添"0"使得位数为 4 的倍数
      Private Function bw(x As Integer, y As String) As String

      Dim r As Integer, i As Integer

      r = x Mod 4

      If r <> 0 Then

        For i = 1 To 4 - r

          y = “0” + y

        Next i

        x = Len(y)

      End If

      bw =   ①   
      End Function

      Private Sub Command1_Click()

         Dim m As String, n As Integer, i As Integer, a As Integer

         Dim s As Integer, s1 As String, j As Integer

         m = Text1.Text

         n = Len(m)

         Text2.Text =“”

         m =  ②           ‘调整m的位数为4的倍数

         For i = 1 To n - 3 Step 4

           s = 0

           For j = i To i + 3

             a = Val(Mid(m, j, 1))

             s =  ③  

           Next j

           If s >= 10 Then

             s1 = Chr(Asc("A") + s - 10)

           Else

             s1 = CStr(s)      ‘函数CStr类似于 Str,但无前导空格

           End If

           Text2.Text = Text2.Text + s1

         Next i
      End Sub

       ② ③

微信扫码预览、分享更方便