快捷搜索:  汽车  科技

16进制转10进制的运用方法(VB16进制转换10进制)

16进制转10进制的运用方法(VB16进制转换10进制)Case "1": b = b 16 ^ (i - 1) * 1 Case "0": b = b 16 ^ (i - 1) * 0 Hex = UCase(Hex) For i = 1 To Len(Hex) Select Case Mid(Hex Len(Hex) - i 1 1)

工业自动化控制中,VB做上位机软件应用广泛,在通讯时,需要使用到的数据转换,今天介绍16进制转换10进制,代码如下:

Function HEX_to_DEC(ByVal Hex As String) As String '十六进制转换十进制度

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

16进制转10进制的运用方法(VB16进制转换10进制)(1)

猜您喜欢: