16 binary binary, octal binary

Source: Internet
Author: User

' Use: Convert binary to octal ' input: Bin (binary number) ' Input data type: String ' output: bin_to_oct (octal number) ' Output data type: String ' The maximum number entered is 2,147,483,647 characters public Function        Bin_to_oct (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 me = 1 to Len (BIN) Step 3 Select case Mid (Bin,             I, 3) case "$": H = h & "0" Case "001": H = h & "1" Case "010": H = h & "2"            Case "011": H = h & ' 3 ' case ": H = H &" 4 "Case" 101 ": H = h &" 5 " Case "a": H = h & "6" Case "111": H = h & "7" End select Next I and Left (H, 1)  = "0" H = right (H, Len (h)-1) wend bin_to_oct = HEnd function ' Purpose: convert hex to binary ' input: Hex (hexadecimal number) ' Input data type: String ' Output: Hex_to_bin (binary number) ' Output data type: String ' The maximum number entered is 2,147,483,647 characters 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 & "$" 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 ' E nd Select Next i while leave (b, 1) = "0" B = right (b, Len (b)-1) wend Hex_to_bin = BEnd function ' use: 10 Hex to octal ' input: Hex (hexadecimal number) ' Input data type: String ' output: hex_to_oct (octal number) ' Output data type: String ' The maximum number entered is 2,147,483,647 characters public Function hex_ To_oct (ByVal Hex as String) As string Dim bin as String Hex = UCase (hex) bin = Hex_to_bin (hex) hex_to_oct = bin_to_oct (Bin) End Function 

16 binary to binary, octal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.