# Re: 怎样把字串"1010101" 转换成数值55Hex ??

Posted by callback on November 06, 1998 at 19:56:19:

In Reply to: 怎样把字串"1010101" 转换成数值55Hex ?? posted by 杀手 on November 06, 1998 at 19:15:07:

我曾写过一个 function,给你参考, 可直接拿来用
用法:
dim strA as string

'Text1内输入 8 bit的二进位字串
strA=gstrBin8ToHex2(text1.text)
_________________________________________

Public Function gstrBin8ToHex2(ByVal strBin8 As String) As String
Dim strHex2 As String * 2 '最后传回值
Dim strTemp As String * 4, strConv As String * 1
Dim bytI As Byte '回圈计数
strHex2 = ""
For bytI = 0 To 1
strTemp = Mid(strBin8, 4 * bytI + 1, 4)
Select Case strTemp
Case "0000": strConv = "0"
Case "0001": strConv = "1"
Case "0010": strConv = "2"
Case "0011": strConv = "3"
Case "0100": strConv = "4"
Case "0101": strConv = "5"
Case "0110": strConv = "6"
Case "0111": strConv = "7"
Case "1000": strConv = "8"
Case "1001": strConv = "9"
Case "1010": strConv = "A"
Case "1011": strConv = "B"
Case "1100": strConv = "C"
Case "1101": strConv = "D"
Case "1110": strConv = "E"
Case "1111": strConv = "F"
Case Else
gstrBin8ToHex2 = "Input Error!"
GoTo gstrBin8ToHex2_end
End Select
strHex2 = strHex2 & strConv
Next bytI
gstrBin8ToHex2 = strHex2
gstrBin8ToHex2_end:
End Function

Follow Ups: