Hex to Byte

G

Gerald

Anyone have a quick code sample showing how to convert a Hex string into a
Byte array?
 
G

Gerald

I figured it out...in case someone else has a need for this, below is a
sample function:

Private Function HexToByte(ByVal HexInput As String) As Byte()
Try
If HexInput.Length > 0 Then
Dim ndx As Integer = 1
Dim i As Integer
Dim ByteCnt As Integer

ByteCnt = HexInput.Length / 2
Dim ByteVar(ByteCnt) As Byte
For i = 0 To ByteCnt - 1
ByteVar(i) = Convert.ToByte(Mid(HexInput, ndx, 2),
16)
ndx = ndx + 2
Next

Return ByteVar

End If

Catch
Err.Raise(Err.Number, "Encryption::HexToByte",
Err.Description)
End Try

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top