Home > Net >  How to convert large Hex to binary values?
How to convert large Hex to binary values?

Time:01-04

I have Hex data like "44783048E0460001" and I want to convert this from Hex to Binary.
Can you please help to share any way. Note: =Hex2Bin(**) -> this has some limitation on range.

Expecting:

0100010001111000001100000100100011100000010001100000000000000001

CodePudding user response:

You can loop through your string and perform this simple translation:

0  0000
1  0001
2  0010
3  0011
4  0100
5  0101
6  0110
7  0111
8  0100
9  1001
A  1010
B  1011
C  1100
D  1101
E  1110
F  1111

Just concatenate everything (using CONCATENATE(), TEXTJOIN() or simple &).

CodePudding user response:

Since every hex-digit is converted to four binary-digits, you could convert digit by digit, e.g. like this:

Public Function Hex2BinEX(h As String) As String
    Dim i As Long
    Dim result As String
    Dim ch As String
    
    For i = 1 To Len(h)
        ch = Mid(h, i, 1)
        result = result & Right("000" & WorksheetFunction.Hex2Bin(ch), 4)
    Next
    Hex2BinEX = result
End Function
  • Related