Hello,
In vb6
eg. string A1 is changed with StringToHex
result is 4131
eg. Hex 4131 is changed with HexToString
result is A1.
Now In b4x
is working.
How can I convert String to Hex without using library?
Thanks.
In vb6
B4X:
Public Function HexToString(ByVal HexToStr As String) As String
Dim strTemp As String
Dim strReturn As String
Dim I As Long
For I = 1 To Len(HexToStr) Step 2
strTemp = Chr(Val("&H" & Mid(HexToStr, I, 2)))
strReturn = strReturn & strTemp
Next I
HexToString = strReturn
End Function
Public Function StringToHex(ByVal StrToHex As String) As String
Dim strTemp As String
Dim strReturn As String
Dim I As Long
For I = 1 To Len(StrToHex)
strTemp = Hex$(Asc(Mid$(StrToHex, I, 1)))
If Len(strTemp) = 1 Then strTemp = "0" & strTemp
strReturn = strReturn & strTemp
Next I
StringToHex = strReturn
End Function
eg. string A1 is changed with StringToHex
result is 4131
eg. Hex 4131 is changed with HexToString
result is A1.
Now In b4x
B4X:
Sub HexToString(HexToStr As String) As String
Dim strTemp As String
Dim strReturn As String
For i=0 To HexToStr.Length -1 Step 2
strTemp= Chr( Bit.ParseInt( HexToStr.SubString2( i, i+2), 16))
strReturn = strReturn & strTemp
Next
Return strReturn
End Sub
is working.
How can I convert String to Hex without using library?
Thanks.