发布网友 发布时间:2022-05-06 05:21
共1个回答
热心网友 时间:2022-06-29 15:32
'16进制转换二进制 Public Function HEX_to_BIN(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 HEX_to_BIN = B End Function '10进制转换二进制 Public Function DEC_to_BIN(Dec 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 '8进制转换二进制 Public Function OCT_to_BIN(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 OCT_to_BIN = B End Function