-
Feb 9th, 2017, 10:01 AM
#1
Thread Starter
Lively Member
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!
-
Feb 9th, 2017, 10:30 AM
#2
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?
-
Feb 9th, 2017, 10:35 AM
#3
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
-
Feb 9th, 2017, 11:39 AM
#4
Thread Starter
Lively Member
Re: Return binary from hex string
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!
-
Feb 9th, 2017, 11:40 AM
#5
Thread Starter
Lively Member
Re: Return binary from hex string
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.
-
Feb 10th, 2017, 05:36 PM
#6
Thread Starter
Lively Member
Re: Return binary from hex string
Hi DEXWERX,
Thanks very much, your code is working
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|