numHex =Integer.Parse(strHex, Globalization.NumberStyles.AllowHexSpecifier)
成都创新互联网络公司拥有十载的成都网站开发建设经验,成百上千客户的共同信赖。提供网站设计、成都做网站、网站开发、网站定制、卖链接、建网站、网站搭建、自适应网站建设、网页设计师打造企业风格,提供周到的售前咨询和贴心的售后服务
或
numHex = Integer. Parse("H" strHex)
10进制转16进制的话可以使用HEX()函数,16进制转10进制没有现成函数,可以使用如下代码实现:
' 用途:将十六进制转化为十进制
' 输入:Hex(十六进制数)
' 输入数据类型:String
' 输出:HEX_to_DEC(十进制数)
' 输出数据类型:Long
' 输入的最大数为7FFFFFFF,输出的最大数为2147483647
Public Function HEX_to_DEC(ByVal Hex As String) As Long
Dim i As Long
Dim B As Long
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, Len(Hex) - i + 1, 1)
Case "0": B = B + 16 ^ (i - 1) * 0
Case "1": B = B + 16 ^ (i - 1) * 1
Case "2": B = B + 16 ^ (i - 1) * 2
Case "3": B = B + 16 ^ (i - 1) * 3
Case "4": B = B + 16 ^ (i - 1) * 4
Case "5": B = B + 16 ^ (i - 1) * 5
Case "6": B = B + 16 ^ (i - 1) * 6
Case "7": B = B + 16 ^ (i - 1) * 7
Case "8": B = B + 16 ^ (i - 1) * 8
Case "9": B = B + 16 ^ (i - 1) * 9
Case "A": B = B + 16 ^ (i - 1) * 10
Case "B": B = B + 16 ^ (i - 1) * 11
Case "C": B = B + 16 ^ (i - 1) * 12
Case "D": B = B + 16 ^ (i - 1) * 13
Case "E": B = B + 16 ^ (i - 1) * 14
Case "F": B = B + 16 ^ (i - 1) * 15
End Select
Next i
HEX_to_DEC = B
End Function
扩展资料:
在VB中将十进制转化为十六进制的函数:
输入:Dec(十进制数)'
输入数据类型:Long'
输出:D2H(十六进制数)'
输出数据类型:String'
输入的最大数为2147483647,
输出最大数为7FFFFFFFPublicFunction D2H(Dec As Long) As String
Dim a As String
D2H = ""
Do While Dec 0
a = CStr(Dec Mod 16) Select Case a Case "10": a = "A"
Case "11": a = "B"
Case "12": a = "C"
Case "13": a = "D"
Case "14": a = "E"
Case "15": a = "F"
End Select
D2H = a D2H
Dec = Dec \ 16 LoopEnd Function
串口通信最终都是用二进制传输的,你用代码把二进制转化成十六进制就可以了。不需要额外设置。