+ Reply to Thread
Results 1 to 5 of 5

4digit HEX as Binary in Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2011
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Exclamation 4digit HEX as Binary in Excel

    Does anyone know how to display a 4digit HEX value as as Binary in Excel?
    Excel only seems to have an accuracy of 10 Binary digits.
    Last edited by dcloney; 03-15-2011 at 09:53 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: 4digit HEX as Binary in Excel

    Welcome to the forum.

    How about a UDF?
    Function HexToBin(ByVal sHex As String, _
                      Optional ByVal iLen As Long = 0, _
                      Optional sSep As String = "") As String
        ' shg 2007
        ' sSep is the nybble separator
        ' no error checking for invalid characters ...
    
        Const s         As String = "0000000100100011010001010110011110001001101010111100110111101111"
        Dim i           As Long
    
        sHex = Replace(sHex, " ", "")
        If iLen <= 0 Then iLen = 4 * Len(sHex)
    
        For i = 1 To Len(sHex)
            HexToBin = HexToBin & sSep & Mid(s, 4 * ("&H" & Mid(sHex, i, 1)) + 1, 4)
        Next i
    
        HexToBin = WorksheetFunction.Rept(sSep & "0000", iLen \ 4) & HexToBin
        HexToBin = Right(HexToBin, iLen + (Len(sHex) - 1) * Len(sSep))
    End Function
    Copy the code to a code module and the apply as, for example,

    =HexToBin("ABCD")

    Adding a Macro to a Code Module
    1. Copy the code from the post
    2. Press Alt+F11 to open the Visual Basic Editor (VBE)
    3. From the menu bar in the VBE window, do Insert > Module
    4. Paste the code in the window that opens
    5. Press Alt+Q to close the VBE and return to Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-15-2011
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: 4digit HEX as Binary in Excel

    No luck im afraid.
    Cheers for the help
    Last edited by shg; 03-15-2011 at 03:50 PM. Reason: deleted spurious quote

  4. #4
    Registered User
    Join Date
    03-15-2011
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: 4digit HEX as Binary in Excel

    Fixed it.
    Accidentally missed part of the code when i was using VBE

    Quote Originally Posted by dcloney View Post
    No luck im afraid.
    Cheers for the help

  5. #5
    Registered User
    Join Date
    03-15-2011
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    7
    l;lhklhkjghghjklghyjkl

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1