重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
10进制转16进制的话可以使用HEX()函数,16进制转10进制没有现成函数,可以使用如下代码实现:
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比夹江网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式夹江网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖夹江地区。费用合理售后完善,十载实体公司更值得信赖。
' 用途:将十六进制转化为十进制
' 输入: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
'此函数用于十进制到二进制
Private Function Bin(Number As Long) As Long
Dim Div_value As String
Do
Div_value = (Number Mod 2) Div_value
Number = Int(Number / 2)
Loop Until Number 2
Bin = Number Div_value
End Function
'此函数用于二进制到十进制
Private Function value_Bin(Number As Long) As Long
Dim Temp_value As Long, Cyc As Long
For Cyc = 0 To Len(Str(Number))
If Cyc = Len(Str(Number)) Then
value_Bin = Temp_value + Val(Mid(Str(Number), Cyc, 1))
Exit For
End If
If Cyc 0 Then Temp_value = (Temp_value + Val(Mid(Str(Number), Cyc, 1))) * 2
Next Cyc
End Function
'====写入以上函数后转值操作:
'十进制到十六进制:Hex(十进制数值)
'十进制到八进制:Oct(十进制数值)
'十进制到二进制:Bin(十进制数值)
'二进制到十进制:value_Bin(二进制数值)
'八进制到十进制:Val("O" 八进制数值)
'十六进制到十进制:Val("H" 十六进制数值)
比如
msgbox DEC_to_BIN(10)
就会返回一个10转换为十进制后的结果
或者简单点就用
VB自带函数:
十进制转八进制:Oct(num)
十六进制转八进制:oct("H" num)
十进制转十六进制:hex(num)
八进制转十六进制:hex("O" num)
十六进制转换为十进制
Dim str As String
str = Text2.Text
Text10.Text = CLng("H" str)
没有“十进制整数型表示范围”的说法,是整型或长整型类型的表示范围,每种数值类型都有常数,如Integer的最大值和最小值:Integer.MaxValue ,Integer.MinValue 。鼠标停留在这个语句上时会显示它的数值的。integer是32位的,大概有个20亿的正负值吧。
在内存中没有所谓得进制或者其他进制,数就是数,什么进制是人自己理解的,而不是计算机。你所谓的
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
vb.net虽也有input语句,但一次只能读取到一个变量中,可以用TextFieldParser类代替,但似乎没以前的方便。不过比以前的更灵活。写入文件Write还是可以用,在Microsoft.VisualBasic.FileIO中。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fileName As String = "E:\User Documents\Master\My Documents\电子阅读\股票\table2.csv"
Using Recrods As New Microsoft.VisualBasic.FileIO.TextFieldParser(fileName) '建立TextFieldParser对象
'MyReader.TextFieldType = FieldType.Delimited
Recrods.SetDelimiters(",") '把字段分隔符设置为","
Dim curRow() As String
Do Until Recrods.EndOfData
curRow = Recrods.ReadFields() '读取记录行,返回字符串数组,所以不同字段类型需要自己转换。
Debug.Print(Join(curRow, vbTab))
Loop
End Using
End Sub