把字符串“12341168C5B7”转换为16进制数存为string型
成都创新互联公司 - 服务器托管,四川服务器租用,成都服务器租用,四川网通托管,绵阳服务器托管,德阳服务器托管,遂宁服务器托管,绵阳服务器托管,四川云主机,成都云主机,西南云主机,服务器托管,西南服务器托管,四川/成都大带宽,机柜大带宽,四川老牌IDC服务商
用shuzi=Convert.ToInt32("12341168C5B7",16)
就ok了。
反之用 shuzi.ToString("X")就行了。
给分!!!
12341168C5B7转换成10进制数就是20014839678391。。
而int32的最大值为2,147,483,647。。所以产生错误。
所以要用int64,它的最大值为9,223,372,036,854,775,807。也就是16位十六进制数0X7FFFFFFFFFFFFFFF。
难道还有比F靠后的数??????
VB.Net自带函数:
十进制转八进制:Oct(num)
十六进制转八进制:oct("H" num)
十进制转十六进制:hex(num)
八进制转十六进制:hex("O" num)
十六进制转换为十进制:CLng("H" num)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(DEC_to_HEX(255))
End Sub
Public Function DEC_to_HEX(ByVal Dec As Long) As String
Dim a As String
DEC_to_HEX = ""
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
DEC_to_HEX = a DEC_to_HEX
Dec = Dec \ 16
Loop
End Function
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