Return binary from hex string
Hi,
I have a very old and big vbp program and the need to send a binary value to an external dll.
Suposse the string strHex contains a long string of hex values.
I need convert it to "binary" value.
dim strHex as string
strHex = "9D624714C76FB3646575E21504779F4AA1F231DB"
.binary = CLng("&H" & strHex)
or
.binary = CDbl("&H" & strHex
these samples returns error 13 type mismatch.
I've read some about BSTR or Byte BSTR but haven't any code in vb6.
Thanks very much!
Re: Return binary from hex string
This hexadecimal string is long to convert it in a single go.
What kind of "binary" do you need? An array of bytes?
Re: Return binary from hex string
Here's a slow snippet I use, that gets the job done.
Code:
Private Function HexBytes(HexStr As String) As Byte()
ReDim Bytes(0 To Len(HexStr) \ 2 - 1) As Byte
Dim i As Long, j As Long
For i = 1 To Len(HexStr) Step 2
Bytes(j) = CByte("&H" & Mid$(HexStr, i, 2))
j = j + 1
Next
HexBytes = Bytes
End Function
Re: Return binary from hex string
Quote:
Originally Posted by
Arnoutdv
This hexadecimal string is long to convert it in a single go.
What kind of "binary" do you need? An array of bytes?
I think yes: array of bytes
Thanks!
Re: Return binary from hex string
Quote:
Originally Posted by
DEXWERX
Here's a slow snippet I use, that gets the job done.
Code:
Private Function HexBytes(HexStr As String) As Byte()
ReDim Bytes(0 To Len(HexStr) \ 2 - 1) As Byte
Dim i As Long, j As Long
For i = 1 To Len(HexStr) Step 2
Bytes(j) = CByte("&H" & Mid$(HexStr, i, 2))
j = j + 1
Next
HexBytes = Bytes
End Function
Thanks very much for your code!
I will test and reply here.
:wave:
Re: Return binary from hex string
Hi DEXWERX,
Thanks very much, your code is working :D