Simple Hex Encode / Decode
Posted: 2003-06-01
By: ArchiveBot
Viewed: 117
Filed Under:
No attachments for this post
Two functions: One to turn an ASCII string into a HEX string, and one to turn a HEX string into an ASCII string.
Original Author: Snytax
Code
'Encodes a string as hex
Public Function sHexEncode(sData As String) As String
Dim iChar As Integer
Dim sOutString As String
Dim sTmpChar As String
For iChar = 1 To Len(sData)
sTmpChar = Hex$(Asc(Mid(sData, iChar, 1)))
If Len(sTmpChar) = 1 Then sTmpChar = "0" & sTmpChar
sOutString = sOutString & sTmpChar
Next iChar
sHexEncode = sOutString
End Function
'Decodes a string from hex
Public Function sHexDecode(sData As String) As String
Dim iChar As Integer
Dim sOutString As String
Dim sTmpChar As String
For iChar = 1 To Len(sData) Step 2
sTmpChar = Chr("&H" & Mid(sData, iChar, 2))
sOutString = sOutString & sTmpChar
Next iChar
sHexDecode = sOutString
End Function
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.