VB--十进制;八进制;十六进制;二进制相互转换大全1.用途:将十进制转化为二进制
' 输入:Dec十进制数
' 输入数据类型:Long
' 输出:DEC_to_BIN二进制数
' 输出数据类型:String
Public Function DEC_to_BINDec As Long As String      DEC_to_BIN = ""
Do While Dec > 0
DEC_to_BIN = Dec Mod 2 & DEC_to_BIN
Dec = Dec \ 2
Loop
End Function
'2. 用途:将二进制转化为十进制
' 输入:Bin二进制数
' 输入数据类型:String
' 输出:BIN_to_DEC十进制数
' 输出数据类型:Long
Public Function BIN_to_DECByVal Bin As String As Long      Dim i As Long
For i = 1 To LenBin
BIN_to_DEC = BIN_to_DEC  2 + ValMidBin; i; 1      Next i
End Function
' 3.用途:将十六进制转化为二进制
' 输入:Hex十六进制数
' 输入数据类型:String
' 输出:HEX_to_BIN二进制数
' 输出数据类型:String
Public Function HEX_to_BINByVal Hex As String As String
Dim i As Long
Dim B As String
Hex = UCaseHex
For i = 1 To LenHex
Select Case MidHex; 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"              C
ase "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 LeftB; 1 = "0"
B = RightB; LenB - 1
Wend
HEX_to_BIN = B
End Function
' 4.用途:将二进制转化为十六进制
' 输入:Bin二进制数二进制转换十六进制数
' 输入数据类型:String
' 输出:BIN_to_HEX十六进制数
' 输出数据类型:String
Public Function BIN_to_HEXByVal Bin As String As String      Dim i As Long
Dim H As String
If LenBin Mod 4 <> 0 Then
Bin = String4 - LenBin Mod 4; "0" & Bin
End If
For i = 1 To LenBin Step 4
Select Case MidBin; i; 4
Case "0000": H = H & "0"
Case "0001": H = H & "1"
Case "0010": H = H & "2"
Case "0011": H = H & "3"

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。