精华内容
下载资源
问答
  • VB.NET 进制转换 2进制 8进制 10进制 16进制 实现互 自己写的代码有不足之处请多包涵
  • vb编写的16进制2进制互源码
  • 十进制数转16进制数字源代码VB程序,演示测试用
  • 摘要:VB源码,算法相关,进制转换 一个VB进制转换程序源代码,将10进制转换成16进制不溢出,范围增大到922337203685477,压缩包内是实例源代码
  • VB校验和,将16进制字符串转为10进制后相加,用于将文本框中的空格去掉,将字符串中回车、换行符去掉。
  • vb进制转十六进制 源码 Visual Basic 6.0
  • vbs-16进制转2进制

    2020-04-14 12:11:06
    '16进制转2进制 'Buf 16进制字符串 Function hexTOBinary(Buf) Buf_len = len(Buf) For i = 1 To Buf_len hex_str = mid(Buf,i,1) binary = "" If hex_str = "0" then binary = "0000" If hex_str = "1" ...
    '16进制转2进制
    'Buf 16进制字符串
    Function hexTOBinary(Buf)
    	Buf_len = len(Buf)
    	For i = 1 To Buf_len
    		hex_str = mid(Buf,i,1)
    		binary = ""
    		If hex_str = "0" then binary = "0000"
    		If hex_str = "1" then binary = "0001"
    		If hex_str = "2" then binary = "0010"
    		If hex_str = "3" then binary = "0011"
    		If hex_str = "4" then binary = "0100"
    		If hex_str = "5" then binary = "0101"
    		If hex_str = "6" then binary = "0110"
    		If hex_str = "7" then binary = "0111"
    		If hex_str = "8" then binary = "1000"
    		If hex_str = "9" then binary = "1001"
    		If hex_str = "a" then binary = "1010"
    		If hex_str = "b" then binary = "1011"
    		If hex_str = "c" then binary = "1100"
    		If hex_str = "d" then binary = "1101"
    		If hex_str = "e" then binary = "1110"
    		If hex_str = "f" then binary = "1111"
    		hexTOBinary = hexTOBinary & binary
    	Next                                
    End Function

     

    展开全文
  • 2进制和10进制的转换

    2018-09-24 21:59:48
    VB代码2进制和10进制的转换,VB有专门的API函数CopyMemory能处理2-10进制浮点数转换和10-2进制浮点数转换。...下列代码演示了10进制Single(单精度浮点型转为16进制字符显示的浮点数和其相反运算:
  • VB的十进制数转换为二进制、八进制、十六进制。 来源网络
  • 实现RGB颜色的调配,使得VB设置RGB颜色时更加直观
  • VB 16进制文件编辑器,只要是16进制的文件,都可使用本编辑器打开并查看源代码内容,使用起来很方便,界面简洁易操作,还可对代码进行区块式的选择、查找替换字符串等操作,运行效果请参见预览图。
  • 在.NET Framework中,System.Convert类...Convert .ToString 方法可以将整数值转换为其指定基数(必须是 2、8、10 或 16)的等效字符串表示形式。即可以将十进制整数转换成二进制、八进制、十进制(无实际意义)或十...

    在.NET Framework中,System.Convert类中的ToString方法和ToInt32(ToInt64)方法都可以方便的实现各种进制间的相互转换。

    1、Convert .ToString 方法

    Convert .ToString 方法可以将整数值转换为其指定基数(必须是 2、8、10 或 16)的等效字符串表示形式。即可以将十进制整数转换成二进制、八进制、十进制(无实际意义)或十六进制数字的字符串。
    Convert .ToString(value,toBase)
    参数:value——整型,要转换的整数;toBase—— System .Int32 ,返回值的基数,必须是 2、8、10 或 16。
    返回值:System .String ,以 toBase 为基的 value 的字符串表示形式。
    如:

            Dim int As Integer = 256
            '十进制转二进制
            Dim str2 As String = Convert.ToString(int, 2)
            '十进制转八进制
            Dim str8 As String = Convert.ToString(int, 8)
            '十进制转十进制
            Dim str10 As String = Convert.ToString(int, 10)
            '十进制转十六进制
            Dim str16 As String = Convert.ToString(int, 16)
            Console.WriteLine("十进制转二进制:" & str2)
            Console.WriteLine("十进制转八进制:" & str8)
            Console.WriteLine("十进制转十进制:" & str10)
            Console.WriteLine("十进制转十六进制:" & str16)
    

    测试结果如图:
    在这里插入图片描述

    2、Convert .ToInt32(ToInt64) 方法

    将指定基数的数字的字符串表示形式转换为等效的整数。即可以将二进制、八进制、十进制(无实际意义)或十六进制整数的字符串表示形式转换为十进制的数字(整型)。
    Convert .ToUInt64(value,fromBase)
    参数:value—— System .String ,包含要转换的数字的字符串;fromBase——System .Int32 ,value 中数字的基数,它必须是 2、8、10 或 16。
    返回值:整型,与 value 中数字等效的 整数,如果 value 为 Nothing,则为 0(零)。
    如:

            '二进制
            Dim str2 As String = "100000000"
            '八进制
            Dim str8 As String = "400"
            '十六进制
            Dim str16 As String = "100"
    
            '二进制转十进制
            Dim int2 As Integer = Convert.ToInt32(str2, 2)
            '八进制转十进制
            Dim int8 As Integer = Convert.ToInt32(str8, 8)
            '十六进制转十进制
            Dim int16 As Integer = Convert.ToInt32(str16, 16)
    

    3、二进制、八进制、十进制或十六进制间任意互转(输出字符串)

    先把字符串转换成十进制数字,再把数字转换成其他进制的字符串。

        Sub Main()
            '二进制
            Dim str2 As String = "100000000"
            '八进制
            Dim str8 As String = "400"
            '十六进制
            Dim str16 As String = "100"
    
            '二进制转十六进制
            Dim str2to16 As String = ConvertString(str2, 2, 16)
            '八进制转十六进制
            Dim str8to16 As String = ConvertString(str8, 8, 16)
            '十六进制转二进制
            Dim str16to2 As String = ConvertString(str16, 16, 2)
        End Sub
        ''' <summary>
        ''' 进制转换
        ''' </summary>
        ''' <param name="value">二进制、八进制、十进制或十六进制整数的字符串表示形式</param>
        ''' <param name="fromBase">与value值中的相对应的基数(2、8、10或16)</param>
        ''' <param name="toBase">要转换成的进制基数(2、8、10或16)</param>
        ''' <returns></returns>
        Private Function ConvertString(ByVal value As String, ByVal fromBase As Int32, ByVal toBase As Int32) As String
            Dim intValue As Integer = Convert.ToInt32(value, fromBase)
    
            Return Convert.ToString(intValue, toBase)
        End Function
    

    4、其他进制转换方法

    Object.ToString方法或String.Format方法可以将十进制整数转换成十六进制的数字字符串表现形式,但没有提供其他进制的转换。
    如:

            Dim int As Integer = 256
            Dim strS As String = int.ToString("x")
            Dim strF As String = String.Format("{0:x}", int)
    

    5、进制基础知识

    比如十进制的15,其二进制为1111,八进制为17,而16进制为F,各种进制之间是如何转换的呢?

    (1)二进制、八进制、十六进制转十进制

    进制转换
    可见,在十进制中,每一位表示10的幂,要知道十进制位所代表的具体数字,可以将相应数字乘以10的幂,然后把结果相加。
    按照同样的方法,二进制中,每一位表示2的幂,则应将数字乘以2的幂,然后把结果相加即可得到相应的十进制数。
    依此类推,八进制和十六进制都可以按此方法转换为十进制。

    (2)十进制转二进制、八进制、十六进制

    方法:除相应进制的基数(如二进制的基数为2、八进制的基数为8、十六进制的基数为16)取余法,即每次将整数部分除以基数,余数为该位权上的数,而商继续除以基数,余数又为上一个位权上的数,这个步骤一直持续下去,直到商为0为止,最后读数时候,从最后一个余数读起,一直到最前面的一个余数。
    例:将十进制的(15)转换为二进制的步骤如下:

    1. 将商15除以2,商7余数为1;
    2. 将商7除以2,商3余数为1;
    3. 将商3除以2,商1余数为1;
    4. 将商1除以2,商0余数为1;
    5. 读数,读数字从最后的余数向前读,1111。

    将十进制的(15)转换为八进制的步骤如下:
    1、 将商15除以8,商1余数为7;
    2、将商1除以8,商0余数为1;
    3、 读数,读数字从最后的余数向前读,17。

    将十进制的(15)转换为十六进制的步骤如下:
    1、 将商15除以16,商0余数为15;
    2、读数,读数字从最后的余数向前读,15,十六进制用字母F表示。

    展开全文
  • 在IFIX中VB进制进制十六进制进制转换代码
  • 到我的博客去哦,有更多的源码下载的………… http://blog.csdn.net/mohongmao/
  • 颜色值转换(RGB与VB十六进制)

    热门讨论 2012-05-16 11:51:23
    颜色值转换(RGB与VB十六进制),在程序开发中经常要用的设置界面颜色,但是用函数非常麻烦,而且增加代码量,所以就开发了这个可以转换的工具
  • VB 实现进制转换,不错的代码,基本支持所有进制。支持 16,10,2,8进制直接的转换。
  • vbs-二进制转16进制

    2020-04-14 12:11:38
    '二进制转16进制 'binary二进制字符串 Function binaryToHex(binary) binary_len = len(binary) quyu = binary_len mod 4 If quyu <> 0 then ss = 5/0 End If hex_len = binary_len/4 For i = 1 To ...
    '二进制转16进制
    'binary二进制字符串
    Function binaryToHex(binary)
    	binary_len = len(binary)
    	quyu = binary_len mod 4
    	If quyu <> 0 then 
    		ss = 5/0
    	End If
    	hex_len = binary_len/4
    	For i = 1 To hex_len
    		start_index = (i-1)*4+1
    		binary_sub = mid(binary,start_index,4)
    		hex_str = ""
    		If binary_sub = "0000" then hex_str = "0"
    		If binary_sub = "0001" then hex_str = "1"
    		If binary_sub = "0010" then hex_str = "2"
    		If binary_sub = "0011" then hex_str = "3"
    		If binary_sub = "0100" then hex_str = "4"
    		If binary_sub = "0101" then hex_str = "5"
    		If binary_sub = "0110" then hex_str = "6"
    		If binary_sub = "0111" then hex_str = "7"
    		If binary_sub = "1000" then hex_str = "8"
    		If binary_sub = "1001" then hex_str = "9"
    		If binary_sub = "1010" then hex_str = "a"
    		If binary_sub = "1011" then hex_str = "b"
    		If binary_sub = "1100" then hex_str = "c"
    		If binary_sub = "1101" then hex_str = "d"
    		If binary_sub = "1110" then hex_str = "e"
    		If binary_sub = "1111" then hex_str = "f"
    		binaryToHex = binaryToHex & hex_str
    	Next
    End Function

     

    展开全文
  • 十六进制转化为浮点数,功能简单,两个测试按钮。 十六进制转化为浮点数,功能简单,两个测试按钮。可以简单了解一下.....
  • 进制转进制进制转化为八进制进制转化为十六进制进制转化为十进制进制转化为二进制进制转化为十六进制进制转进制进制转化为八进制进制转化为十六进制 十六进制转化为二...

    原文地址: http://www.newxing.com/Tech/Program/VisualBasic/748.html
    模块包含了下面的各种转换:
    
    
    二进制转十进制
    二进制转化为八进制
    二进制转化为十六进制
    
    八进制转化为十进制
    八进制转化为二进制
    八进制转化为十六进制
    
    十进制转二进制
    十进制转化为八进制
    十进制转化为十六进制
    
    十六进制转化为二进制
    十六进制转化为八进制
    十六进制转化为十进制
    
    16进制转ASC
    10进制长整数转4位16进制字符串
    10进制长整数转2位16进制字符串
    ASCII字符串转16进制字符串
    反16进制数转10进制数,共8位
    反16进制数转10进制数,共6位
    反16进制数转10进制数,共4位
    10进制数转反16进制数,共8位
    0进制数转反16进制数,共6位
    10进制数转反16进制数,共4位
    记录集转二进制流
    ASCII码转二进制流
    二进制流转ASCII码
    
    VBScript code复制代码'二进制转十进制
    Public Function B2D(vBStr As String) As Long
         Dim vLen As Integer  '串长
         Dim vDec As Long     '结果
         Dim vG As Long       '权值
         Dim vI As Long       '位数
         Dim vTmp As String   '临时串
         Dim vN As Long       '中间值
    
        vLen = Len(vBStr)
    
        vG = 1 '初始权值
         vDec = 0   '结果初值
         B2D = vDec '返回初值
    
        For vI = vLen To 1 Step -1
             vTmp = Mid(vBStr, vI, 1) '取出当前位
             vN = Val(vTmp)
    
            If vN < 2 Then  '判断是不是合法二进制串,貌似不严谨,E文和符号会被判0而合法
                 vDec = vDec + vG * vN '得到中间结果
                 vG = vG + vG
             Else
                 vDec = 0
                 'msgbox "不是有效的二进制数",vbokonly
                 Exit Function
             End If
        Next vI
    
        B2D = vDec
    End Function
    
    '十进制转二进制
    Public Function D2B(Dec As Long) As String
         D2B = ""
         Do While Dec > 0
             D2B = Dec Mod 2 & D2B
             Dec = Dec \ 2
         Loop
    End Function
    
    ' 用途:将十六进制转化为二进制
    ' 输入:Hex(十六进制数)
    ' 输入数据类型:String
    ' 输出:H2B(二进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647个字符
    Public Function H2B(ByVal Hex As String) As String
         Dim i As Long
         Dim b As String
        
        Hex = UCase(Hex)
         For i = 1 To Len(Hex)
             Select Case Mid(Hex, i, 1)
                 Case "0": b = b & "0000"
                 Case "1": b = b & "0001"
                 Case "2": b = b & "0010"
                 Case "3": b = b & "0011"
                 Case "4": b = b & "0100"
                 Case "5": b = b & "0101"
                 Case "6": b = b & "0110"
                 Case "7": b = b & "0111"
                 Case "8": b = b & "1000"
                 Case "9": b = b & "1001"
                 Case "A": b = b & "1010"
                 Case "B": b = b & "1011"
                 Case "C": b = b & "1100"
                 Case "D": b = b & "1101"
                 Case "E": b = b & "1110"
                 Case "F": b = b & "1111"
             End Select
         Next i
         While Left(b, 1) = "0"
             b = Right(b, Len(b) - 1)
         Wend
         H2B = b
    End Function
    
    ' 用途:将二进制转化为十六进制
    ' 输入:Bin(二进制数)
    ' 输入数据类型:String
    ' 输出:B2H(十六进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647个字符
    Public Function B2H(ByVal Bin As String) As String
         Dim i As Long
         Dim H As String
         If Len(Bin) Mod 4 <> 0 Then
             Bin = String(4 - Len(Bin) Mod 4, "0") & Bin
         End If
        
        For i = 1 To Len(Bin) Step 4
             Select Case Mid(Bin, i, 4)
                 Case "0000": H = H & "0"
                 Case "0001": H = H & "1"
                 Case "0010": H = H & "2"
                 Case "0011": H = H & "3"
                 Case "0100": H = H & "4"
                 Case "0101": H = H & "5"
                 Case "0110": H = H & "6"
                 Case "0111": H = H & "7"
                 Case "1000": H = H & "8"
                 Case "1001": H = H & "9"
                 Case "1010": H = H & "A"
                 Case "1011": H = H & "B"
                 Case "1100": H = H & "C"
                 Case "1101": H = H & "D"
                 Case "1110": H = H & "E"
                 Case "1111": H = H & "F"
             End Select
         Next i
         While Left(H, 1) = "0"
             H = Right(H, Len(H) - 1)
         Wend
         B2H = H
    End Function
    
    ' 用途:将十六进制转化为十进制
    ' 输入:Hex(十六进制数)
    ' 输入数据类型:String
    ' 输出:H2D(十进制数)
    ' 输出数据类型:Long
    ' 输入的最大数为7FFFFFFF,输出的最大数为2147483647
    Public Function H2D(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
         H2D = b
    End Function
    
    ' 用途:将十进制转化为十六进制
    ' 输入:Dec(十进制数)
    ' 输入数据类型:Long
    ' 输出:D2H(十六进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647,输出最大数为7FFFFFFF
    Public Function 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
         Loop
    End Function
    
    ' 用途:将十进制转化为八进制
    ' 输入:Dec(十进制数)
    ' 输入数据类型:Long
    ' 输出:D2O(八进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647,输出最大数为17777777777
    Public Function D2O(Dec As Long) As String
         D2O = ""
         Do While Dec > 0
             D2O = Dec Mod 8 & D2O
             Dec = Dec \ 8
         Loop
    End Function
    
    ' 用途:将八进制转化为十进制
    ' 输入:Oct(八进制数)
    ' 输入数据类型:String
    ' 输出:O2D(十进制数)
    ' 输出数据类型:Long
    ' 输入的最大数为17777777777,输出的最大数为2147483647
    Public Function O2D(ByVal Oct As String) As Long
         Dim i As Long
         Dim b As Long
        
        For i = 1 To Len(Oct)
             Select Case Mid(Oct, Len(Oct) - i + 1, 1)
                 Case "0": b = b + 8 ^ (i - 1) * 0
                 Case "1": b = b + 8 ^ (i - 1) * 1
                 Case "2": b = b + 8 ^ (i - 1) * 2
                 Case "3": b = b + 8 ^ (i - 1) * 3
                 Case "4": b = b + 8 ^ (i - 1) * 4
                 Case "5": b = b + 8 ^ (i - 1) * 5
                 Case "6": b = b + 8 ^ (i - 1) * 6
                 Case "7": b = b + 8 ^ (i - 1) * 7
             End Select
         Next i
         O2D = b
    End Function
    
    ' 用途:将二进制转化为八进制
    ' 输入:Bin(二进制数)
    ' 输入数据类型:String
    ' 输出:B2O(八进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647个字符
    Public Function B2O(ByVal Bin As String) As String
         Dim i As Long
         Dim H As String
         If Len(Bin) Mod 3 <> 0 Then
             Bin = String(3 - Len(Bin) Mod 3, "0") & Bin
         End If
        
        For i = 1 To Len(Bin) Step 3
             Select Case Mid(Bin, i, 3)
                 Case "000": H = H & "0"
                 Case "001": H = H & "1"
                 Case "010": H = H & "2"
                 Case "011": H = H & "3"
                 Case "100": H = H & "4"
                 Case "101": H = H & "5"
                 Case "110": H = H & "6"
                 Case "111": H = H & "7"
             End Select
         Next i
         While Left(H, 1) = "0"
             H = Right(H, Len(H) - 1)
         Wend
         B2O = H
    End Function
    
    ' 用途:将八进制转化为二进制
    ' 输入:Oct(八进制数)
    ' 输入数据类型:String
    ' 输出:O2B(二进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647个字符
    Public Function O2B(ByVal Oct As String) As String
         Dim i As Long
         Dim b As String
        
        For i = 1 To Len(Oct)
             Select Case Mid(Oct, i, 1)
                 Case "0": b = b & "000"
                 Case "1": b = b & "001"
                 Case "2": b = b & "010"
                 Case "3": b = b & "011"
                 Case "4": b = b & "100"
                 Case "5": b = b & "101"
                 Case "6": b = b & "110"
                 Case "7": b = b & "111"
             End Select
         Next i
         While Left(b, 1) = "0"
             b = Right(b, Len(b) - 1)
         Wend
         O2B = b
    End Function
    
    ' 用途:将八进制转化为十六进制
    ' 输入:Oct(八进制数)
    ' 输入数据类型:String
    ' 输出:O2H(十六进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647个字符
    Public Function O2H(ByVal Oct As String) As String
         Dim Bin As String
         Bin = O2B(Oct)
         O2H = B2H(Bin)
    End Function
    
    ' 用途:将十六进制转化为八进制
    ' 输入:Hex(十六进制数)
    ' 输入数据类型:String
    ' 输出:H2O(八进制数)
    ' 输出数据类型:String
    ' 输入的最大数为2147483647个字符
    Public Function H2O(ByVal Hex As String) As String
         Dim Bin As String
         Hex = UCase(Hex)
         Bin = H2B(Hex)
         H2O = B2O(Bin)
    End Function
    
    '====================================================
    
    '16进制转ASC
    Function H2A(InputData As String) As String
      Dim mydata
      mydata = Chr(Val("&H" & InputData))
      H2A = mydata
      Exit Function
    End Function
    
    '10进制长整数转4位16进制字符串
    Function S2H(Num As Long) As String
    Dim mynum As String
    mynum = Hex(Num)
    If Len(mynum) = 1 Then mynum = "000" + mynum
    If Len(mynum) = 2 Then mynum = "00" + mynum
    If Len(mynum) = 3 Then mynum = "0" + Left(mynum, 2) + Right(mynum, 1)
    If Len(mynum) = 4 Then mynum = Right(mynum, 2) + Left(mynum, 2)
    S2H = mynum
    End Function
    
    '10进制长整数转2位16进制字符串
    Function S2H2(Num As Long) As String
    Dim mynum As String
    mynum = Hex(Num)
    If Len(mynum) = 1 Then mynum = "0" + mynum
    S2H2 = mynum
    End Function
    
    'ASCII字符串转16进制字符串
    Public Function A2H(str As String) As String
    Dim strlen As Integer
    Dim i As Integer
    Dim mystr As String
    mystr = ""
    strlen = Len(str)
    For i = 1 To strlen Step 1
    mystr = mystr + Hex$(Asc(Mid(str, i, 1)))
    Next i
    A2H = mystr
    End Function
    
    '=====================================================
    '进制反转
    '=====================================================
    
    '反16进制数转10进制数,共8位
    Function FHexToInt(ByVal str As String) As String
        Dim text1 As String
        text1 = str
        Dim text2 As String
        text2 = Mid(text1, 7, 2)
        Dim text3 As String
        text3 = Mid(text1, 5, 2)
        Dim text4 As String
        text4 = Mid(text1, 3, 2)
        Dim text5 As String
        text5 = Mid(text1, 1, 2)
        FHexToInt = Val("&H" & text2 & text3 & text4 & text5)
        Exit Function
    End Function
    '反16进制数转10进制数,共6位
    Function FHexToInt6(ByVal str As String) As String
        Dim text1 As String
        text1 = str
        Dim text2 As String
        text2 = Mid(text1, 5, 2)
        Dim text4 As String
        text3 = Mid(text1, 3, 2)
        Dim text5 As String
        text4 = Mid(text1, 1, 2)
        FHexToInt6 = Val("&H" & text2 & text3 & text4)
        Exit Function
    End Function
    
    '反16进制数转10进制数,共4位
    Function FHexToInt4(ByVal str As String) As String
        Dim text1 As String
        text1 = str
        Dim text2 As String
        text2 = Mid(text1, 3, 2)
        Dim text4 As String
        text3 = Mid(text1, 1, 2)
        FHexToInt4 = Val("&H" & text2 & text3)
        Exit Function
    End Function
    
    '10进制数转反16进制数,共8位
    Function IntToFHex(ByVal nums As Long) As String
        Dim text1 As String
        'text1 = Convert.ToString(nums, &H10)
        text1 = O2H(nums)
        If (Len(text1) = 1) Then
            text1 = ("0000000" & text1)
        End If
        If (Len(text1) = 2) Then
            text1 = ("000000" & text1)
        End If
        If (Len(text1) = 3) Then
            text1 = ("00000" & text1)
        End If
        If (Len(text1) = 4) Then
            text1 = ("0000" & text1)
        End If
        If (Len(text1) = 5) Then
            text1 = ("000" & text1)
        End If
        If (Len(text1) = 6) Then
            text1 = ("00" & text1)
        End If
        If (Len(text1) = 7) Then
            text1 = ("0" & text1)
        End If
        Dim text2 As String
        text2 = Mid(text1, 7, 2)
        Dim text3 As String
        text3 = Mid(text1, 5, 2)
        Dim text4 As String
        text4 = Mid(text1, 3, 2)
        Dim text5 As String
        text5 = Mid(text1, 1, 2)
        IntToFHex = text2 & text3 & text4 & text5
        Exit Function
    End Function
    '10进制数转反16进制数,共6位
    Function IntToFHex6(ByVal nums As Long) As String
        Dim text1 As String
        text1 = O2H(nums)
        If (Len(text1) = 1) Then
            text1 = ("00000" & text1)
        End If
        If (Len(text1) = 2) Then
            text1 = ("0000" & text1)
        End If
        If (Len(text1) = 3) Then
            text1 = ("000" & text1)
        End If
        If (Len(text1) = 4) Then
            text1 = ("00" & text1)
        End If
        If (Len(text1) = 5) Then
            text1 = ("0" & text1)
        End If
        Dim text2 As String
        text2 = Mid(text1, 5, 2)
        Dim text3 As String
        text3 = Mid(text1, 3, 2)
        Dim text4 As String
        text4 = Mid(text1, 1, 2)
        IntToFHex6 = text2 & text3 & text4
        Exit Function
    End Function
    
    '10进制数转反16进制数,共4位
    Function IntToFHex4(ByVal nums As Long) As String
        Dim text1 As String
        text1 = O2H(nums)
        If (Len(text1) = 1) Then
            text1 = ("000" & text1)
        End If
        If (Len(text1) = 2) Then
            text1 = ("00" & text1)
        End If
        If (Len(text1) = 3) Then
            text1 = ("0" & text1)
        End If
        Dim text2 As String
        text2 = Mid(text1, 3, 2)
        Dim text3 As String
        text3 = Mid(text1, 1, 2)
        IntToFHex4 = text2 & text3
        Exit Function
    End Function
    
    '==========================================
    
    Public Function B2S(ByVal str As Byte)
        strto = ""
        For i = 1 To LenB(str)
           If AscB(MidB(str, i, 1)) > 127 Then
               strto = strto & Chr(AscB(MidB(str, i, 1)) * 256 + AscB(MidB(str, i + 1, 1)))
               i = i + 1
           Else
               strto = strto & Chr(AscB(MidB(str, i, 1)))
           End If
        Next
        B2S = strto
    End Function
    
    Public Function V2H(ByVal sHex As String, Optional bUnicode As Boolean)
        Dim sByte As Variant
        Dim byChar() As Byte
        Dim i As Long
        sHex = Replace(sHex, vbCrLf, "")
        sByte = Split(sHex, " ")
        ReDim byChar(0 To UBound(sByte)) As Byte
        For i = 0 To UBound(sByte)
            byChar(i) = Val("&h" & sByte(i))
        Next
        If bUnicode Then
            V2H = byChar
        Else
            V2H = StrConv(byChar, vbUnicode)
        End If
    End Function
    
    '记录集转二进制流
    
    Public Function R2B(rs As Recordset) As Variant              '记录集转换为二进制数据
        Dim objStream As Stream
        Set objStream = New Stream
        objStream.Open
        objStream.Type = adTypeBinary
        rs.Save objStream, adPersistADTG
        objStream.Position = 0
        R2B = objStream.Read()
        Set objStream = Nothing
    End Function
    
    'ASCII码转二进制流
    
    Public Function A2B(str As String) As Variant
       Dim a() As Byte, s As String
       s = str
       a = StrConv(s, vbFromUnicode) '字符串转换为byte型 'a 是byte数组,你可以在程序中调用 ,但不能在textbox中显示。
       A2B = a
    End Function
    
    '二进制流转ASCII码
    
    Public Function B2A(vData As Variant) As String
       Dim s As String
       s = StrConv(vData, vbUnicode) 'byte型转换为字符串
       B2A = s
    End Function
    

    展开全文
  • 如何将10进制16进制,又如何将16进制成10进制,本文将介绍C#和VB实现代码,需要了解的朋友可以参考下
  • 内容索引:VB源码,字符处理,校验和 VB校验和,将16进制字符串转为10进制后相加,用于将文本框中的空格去掉,将字符串中回车、换行符去掉。
  • vb 16进制编码解码

    2013-01-04 13:25:13
    '参数:要编码的内容,分隔符 UnicodeEncode(strContent As String, Optional sp As String) '参数:要解码的内容,分隔符 UnicodeDecode(strUnicode As String, Optional sp As String)
  • 浮点数和十六进制数的相互转换,包括:1.单精度浮点数(32位)和十六进制数的相互转换,2.双精度浮点数(64位)和十六进制数的相互转换。
  • 在上位机与下位机进行数据通讯时,经常传入的为十六进制(HEX),因某些需要对数据进行解包分为二进制的数据进行分析,这里用VB6.0编写了一个小工具,也许让你能用得上!
  • 进制转十六进制vb6程序

    千次阅读 2015-12-04 10:05:48
    【原】二进制转十六进制vb6程序 Private Sub Command1_Click()  Dim strN As String, iHex As String, strBin(), strHex()  Dim intXh As Integer, i As Integer, j As Integer, strTmp ...
  • VBA实现单精度浮点数与十六进制字符串相互转换,并提供2个相互转换的示例 第一个按钮: "A1录入十六进制8位字符串; B1输出单精度浮点数结果" 第二个按钮 "将B1作为单精度浮点数输入 C1输出16进制结果
  • 模块包含了下面的各种转换: 二进制十进制二进制转化为八进制二进制转化为十六进制 八进制转化为十进制...16进制转ASC10进制长整数4位16进制字符串10进制长整数转216进制字符串ASCII字符串转16进制字符串反16...
  • 1.VB进制Byte()数组转换成十六进制字符串函数: Private Function BytesToHex(bytB() As Byte) As StringDim strTmp As String, i As LongFor i = 1 To UBound(bytB)strTmp = strTmp &amp; " " &...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 11,784
精华内容 4,713
关键字:

vb16进制转2进制代码