On Sep 1, 2006, at 12:45 PM, Chris Jett wrote:
I drawing a blank since I have been working on a project for
several days. What is the most efficient way to go about
converting a text string to its hex equivalent?
Function HexLC(s As String) As String
Dim m, source As MemoryBlock
Dim k, mpos, size, b As Integer
Static mHexCode As MemoryBlock
If (mHexCode Is Nil) Then
mHexCode = NewMemoryBlock(16)
mHexCode.Byte(0) = &h30
mHexCode.Byte(1) = &h31
mHexCode.Byte(2) = &h32
mHexCode.Byte(3) = &h33
mHexCode.Byte(4) = &h34
mHexCode.Byte(5) = &h35
mHexCode.Byte(6) = &h36
mHexCode.Byte(7) = &h37
mHexCode.Byte(8) = &h38
mHexCode.Byte(9) = &h39
mHexCode.Byte(10) = &h61
mHexCode.Byte(11) = &h62
mHexCode.Byte(12) = &h63
mHexCode.Byte(13) = &h64
mHexCode.Byte(14) = &h65
mHexCode.Byte(15) = &h66
End If
size = s.LenB - 1
if s.LenB < 1 then return ""
source = s
m = NewMemoryBlock(source.Size * 2)
For k = 0 To size
m.Byte(mpos) = mHexCode.Byte(source.Byte(k) \ 16)
m.Byte(mpos + 1) = mHexCode.Byte(source.Byte(k) Mod 16)
mpos = mpos + 2
Next
Return DefineEncoding(m.StringValue(0, m.size), Encodings.ASCII)
End Function
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>