先上代码:
'文本转16进制
Public Function StrtoHex(ByVal strs As String) As String 'str to 16
Dim abytS() As Byte
Dim bytTemp As Byte
Dim strTemp As String
Dim lLocation As Long
abytS = StrConv(strs, vbFromUnicode)
For lLocation = 0 To UBound(abytS)
bytTemp = abytS(lLocation)
strTemp = Hex(bytTemp)
strTemp = Right("00" & strTemp, 2)
StrtoHex = StrtoHex & strTemp
Next lLocation
End Function'16进制转文本
Public Function HextoStr(ByVal strs As String) As String '16 to str
Dim i As Integer, tmp As String
If Len(strs) Mod 2 Then Exit Function
For i = 1 To Len(strs) Step 2
n = Val("&H" & Mid(strs, i, 2))
If n < 0 Or n > 127 Then
n = Val("&H" & Mid(strs, i, 4))
i = i + 2
End If
tmp = tmp & Chr(n)
Next i
HextoStr = tmp
End Function使用这两个方法转换16进制和文本时,
比如我要把555转换成16进制,16进制栏里就是353535
怎么让它转换的结果变成35 35 35或35|35|35 ?
怎么弄?16进制转文本时也要这样的.
'文本转16进制
Public Function StrtoHex(ByVal strs As String) As String 'str to 16
Dim abytS() As Byte
Dim bytTemp As Byte
Dim strTemp As String
Dim lLocation As Long
abytS = StrConv(strs, vbFromUnicode)
For lLocation = 0 To UBound(abytS)
bytTemp = abytS(lLocation)
strTemp = Hex(bytTemp)
strTemp = Right("00" & strTemp, 2)
StrtoHex = StrtoHex & strTemp
Next lLocation
End Function'16进制转文本
Public Function HextoStr(ByVal strs As String) As String '16 to str
Dim i As Integer, tmp As String
If Len(strs) Mod 2 Then Exit Function
For i = 1 To Len(strs) Step 2
n = Val("&H" & Mid(strs, i, 2))
If n < 0 Or n > 127 Then
n = Val("&H" & Mid(strs, i, 4))
i = i + 2
End If
tmp = tmp & Chr(n)
Next i
HextoStr = tmp
End Function使用这两个方法转换16进制和文本时,
比如我要把555转换成16进制,16进制栏里就是353535
怎么让它转换的结果变成35 35 35或35|35|35 ?
怎么弄?16进制转文本时也要这样的.
解决方案 »
- 请教一个asp的问题
- 制作安装项目如何在桌面放置主程序的快捷方式?
- 看看中关村现在在干什么
- 在动态改变数据源的情况下,我想在水晶报表中加入一个text显示制表人的信息,要怎么做呀?
- mschart的使用
- 如何用VB实现象QQ右下角的来消息闪动QQ图标功能?用于内网办公系统
- 救命,用PQMAGIC动态分区时突然断电,丢失了一个分区,如何恢复??望斑竹手下留情!!
- 急~~~如何从文件中取值赋给动态数组?~~~~在线等待
- 谁帮我解决这个问题,小弟作牛做马报答(另:为什么我只能给20分?我有很多分)
- 我出188分!!!求VB5.0英文版文件,setup1子目录下的全部文件!!!
- 网上下载了IE BHO vb band源码,但是总是找不到引用 "IObjectwithSite & band interfaces v2.10-Eduard
- 怎么才能使shape1控件覆盖住绘制的圆
Private Sub Command1_Click()
Text1.Text = StringPutToHEX("555")
Text2.Text = StringGetByHEX("D0 A1 CF C9 C3 C3 CA C7 B8 F6 BA C3 BA A2 D7 D3")
End SubFunction StringPutToHEX(ByRef pString As String, Optional pLineWidth As Long = 16, Optional ByVal pLimit As String = " ") As String
Dim tSurBytes() As Byte, tSurBytes_Index As Long
Dim tDesBytes() As Byte, tDesBytes_Index As Long, tDesBytes_Length As Long
Dim tLimitCode As Byte
tSurBytes() = StrConv(pString, vbFromUnicode)
tLimitCode = Asc(pLimit)
tDesBytes_Length = UBound(tSurBytes()) * 3 + 2
ReDim tDesBytes(tDesBytes_Length)
For tDesBytes_Index = 0 To tDesBytes_Length Step 3
tDesBytes(tDesBytes_Index) = HexEnCode(tSurBytes(tSurBytes_Index) \ 16)
tDesBytes(tDesBytes_Index + 1) = HexEnCode(tSurBytes(tSurBytes_Index) Mod 16)
tDesBytes(tDesBytes_Index + 2) = tLimitCode
tSurBytes_Index = tSurBytes_Index + 1
Next
StringPutToHEX = StrConv(tDesBytes, vbUnicode)
End FunctionFunction StringGetByHEX(ByRef pHEX As String) As String
Dim tSurBytes() As Byte, tSurBytes_Index As Long
Dim tDesBytes() As Byte, tDesBytes_Index As Long, tDesBytes_Length As Long
tSurBytes() = StrConv(pHEX, vbFromUnicode)
tDesBytes_Length = UBound(tSurBytes()) \ 3
ReDim tDesBytes(tDesBytes_Length)
For tDesBytes_Index = 0 To tDesBytes_Length
tDesBytes(tDesBytes_Index) = HexDeCode(tSurBytes(tSurBytes_Index)) * 16 + HexDeCode(tSurBytes(tSurBytes_Index + 1))
tSurBytes_Index = tSurBytes_Index + 3
Next
StringGetByHEX = StrConv(tDesBytes, vbUnicode)
End FunctionFunction HexEnCode(pHEX As Byte) As Byte
HexEnCode = 48 + pHEX + ((pHEX > 9) And 7)
End FunctionFunction HexDeCode(pHEX As Byte) As Byte
HexDeCode = pHEX - (48 + ((pHEX > 64) And 7))
End Function
'文本转16进制
Public Function StrtoHex(ByVal strs As String) As String 'str to 16
Dim abytS() As Byte
Dim bytTemp As Byte
Dim strTemp As String
Dim lLocation As Long
abytS = StrConv(strs, vbFromUnicode)
For lLocation = 0 To UBound(abytS)
bytTemp = abytS(lLocation)
strTemp = Hex(bytTemp)
strTemp = Right("00" & strTemp, 2)
StrtoHex = StrtoHex & strTemp & " "
Next lLocation
StrtoHex = RTrim(StrtoHex)
End Function'16进制转文本
Public Function HextoStr(ByVal strs As String) As String '16 to str
Dim i As Integer, tmp As String
If Len(strs) Mod 2 Then Exit Function
For i = 1 To Len(strs) Step 2
n = Val("&H" & Mid(strs, i, 2))
If n < 0 Or n > 127 Then
n = Val("&H" & Mid(strs, i, 4))
i = i + 2
End If
tmp = tmp & Chr(n) & " "
Next i
HextoStr = RTrim(tmp)
End Function
555倒是能转换成35 35 35
可是35 35 35转换文本时就有问题了,转换成5 5了.
我再试试KiteGirl的办法.