HEXtoASCII——十六进制转ASCII程序

程序功能为将一串HEX转为ASCII,自动忽略其中的00(表示空)。

4

必须控件:TextBox1,TextBox2,Button1

源代码如下:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim HexNum, i As Single
        Dim aim As String
        Dim input, step1 As String
        i = 1
        input = TextBox1.Text
        step1 = Replace(input, " ", "")
        step1 = Replace(step1, "00", "")

        HexNum = 0.5 * Len(step1) - 1

        Dim hex(HexNum) As String

        For j = 0 To HexNum Step 1
            hex(j) = Mid(step1, i, 2)
            i = i + 2
        Next j

        Dim ascii(HexNum) As String

        For i = 0 To HexNum Step 1
            ascii(i) = Chr(Val("&H" & hex(i)))  '转换为字符 利用数值转换
        Next i
        For j = 0 To HexNum
            aim = aim + ascii(j)
        Next
        TextBox2.Text = aim
End Sub

在visual studio 2012 express for desktop/windows8 pro下编译通过。

已编译好的程序如下:(需要.net运行环境支持)

HEXtoASCII

发布者

《HEXtoASCII——十六进制转ASCII程序》上有3条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注