'HEX转汉字
'如H2A("D2BBB6FEC8FDCBC4CEE5")
'返回:一二三四五
Public Function Hex2Ascii(sText As String) As String
If Len(sText) Mod 2 <> 0 Then sText = "0" & sText
Dim arr() As Byte
ReDim arr(Len(sText) 2 - 1) As Byte
Dim xx As Long
For xx = 0 To Len(sText) 2 - 1
arr(xx) = "&h" & Mid(sText, (xx * 2) + 1, 2)
Next
Hex2Ascii = StrConv(arr, vbUnicode)
End Function
'带有汉字的ASCII字符转HEX
'如:Ascii2Hex("一二三四五")
'返回:D2 BB B6 FE C8 FD CB C4 CE E5
Public Function Ascii2Hex(sText As String) As String
Dim i As Long
Dim hzByte() As Byte
hzByte = StrConv(sText, vbFromUnicode)
For i = 0 To UBound(hzByte)
Ascii2Hex = Ascii2Hex & Hex(hzByte(i)) & " "
Next
Ascii2Hex = Trim$(Hz2Hex)
'转回汉字
'Ascii2Hex = StrConv(hzByte, vbUnicode)
End Function
'HEX转汉字
'如H2A("D2BBB6FEC8FDCBC4CEE5")
'返回:一二三四五
Public Function Hex2Ascii(sText As String) As String
If Len(sText) Mod 2 <> 0 Then sText = "0" & sText
Dim arr() As Byte
ReDim arr(Len(sText) 2 - 1) As Byte
Dim xx As Long
For xx = 0 To Len(sText) 2 - 1
arr(xx) = "&h" & Mid(sText, (xx * 2) + 1, 2)
Next
Hex2Ascii = StrConv(arr, vbUnicode)
End Function
'带有汉字的ASCII字符转HEX
'如:Ascii2Hex("一二三四五")
'返回:D2 BB B6 FE C8 FD CB C4 CE E5
Public Function Ascii2Hex(sText As String) As String
Dim i As Long
Dim hzByte() As Byte
hzByte = StrConv(sText, vbFromUnicode)
For i = 0 To UBound(hzByte)
Ascii2Hex = Ascii2Hex & Hex(hzByte(i)) & " "
Next
Ascii2Hex = Trim$(Hz2Hex)
'转回汉字
'Ascii2Hex = StrConv(hzByte, vbUnicode)
End Function
一周热门 更多>