Hex string to binary

drgs

New member
Local time
Today, 05:45
Joined
Sep 24, 2013
Messages
4
Hello,

I have a text column with hexadecimal strings like "4E1B0A65FE3299FE", ie. of length 16.

I'm doing an ALTER COLUMN query to convert the column to varbinary, but Access is doing conversion by ASCII, which results in a varbinary field of size 32, I think this is because the text column is in Unicode.

SQL Server has something called "styles" which are used with CONVERT
where you can choose to convert by two characters at a time 2:1...

How do I do the same in an Access query? CONVERT/CAST are no supported.
It is an VBA script in Excel...

Thanks,
MK
 
Searching for a hex2bin vba procedure i came accress this little fellow:
Code:
Public Function HEX2BIN(strHex As String) As String
    Dim c As Long, i As Long, b As String * 4, j As Long
    For c = 1 To Len(strHex)
        b = "0000"
        j = 0
        i = Val("&H" & Mid$(strHex, c, 1))
        While i > 0
            Mid$(b, 4 - j, 1) = i Mod 2
            i = i \ 2
            j = j + 1
        Wend
        HEX2BIN = HEX2BIN & b & " "
    Next
    HEX2BIN = RTrim$(HEX2BIN)
End Function

HTH:D
 

Users who are viewing this thread

Back
Top Bottom