indy500fan
asked on
Converting ASCII to HEX
Friends,
I am recieving a serial stream of characters in ASCII, and once I have a valid string of these ASCII characters, I need to convert them to HEX.
I have created a sample app, with a sample string, but it doesn't work. It only converts the First ASCII character to HEX, and ignores the rest.
What do I need to do to convert all of the characters?
Here is my sample app:
Public Class AYFSMain
Dim DelphiString As String = "ñ]¬ªªUUwwE"
Dim DelphiStringHex As String = Hex(Asc(DelphiString))
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(DelphiStri ngHex, "Result", MessageBoxButtons.OK, MessageBoxIcon.Information )
End Sub
End Class
I am recieving a serial stream of characters in ASCII, and once I have a valid string of these ASCII characters, I need to convert them to HEX.
I have created a sample app, with a sample string, but it doesn't work. It only converts the First ASCII character to HEX, and ignores the rest.
What do I need to do to convert all of the characters?
Here is my sample app:
Public Class AYFSMain
Dim DelphiString As String = "ñ]¬ªªUUwwE"
Dim DelphiStringHex As String = Hex(Asc(DelphiString))
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(DelphiStri
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works with one little tweak.
I needed to change For x = 1 To Len... to For x = 0. Other than that, PERFECT!
Thanks!
I needed to change For x = 1 To Len... to For x = 0. Other than that, PERFECT!
Thanks!
Yes, I miss that!
:-)
:-)
Just another way...
Dim DelphiString As String = "ñ]¬ªªUUwwE"
Dim ConvertedToHex As String = ""
For Each MyCharArray As Char In DelphiString.ToCharArray()
ConvertedToHex += Hex(Asc(MyCharArray))
Next
MessageBox.Show(ConvertedT oHex, "Result", MessageBoxButtons.OK, MessageBoxIcon.Information )
Dim DelphiString As String = "ñ]¬ªªUUwwE"
Dim ConvertedToHex As String = ""
For Each MyCharArray As Char In DelphiString.ToCharArray()
ConvertedToHex += Hex(Asc(MyCharArray))
Next
MessageBox.Show(ConvertedT
ASKER
DarrenD,
Hey, that's pretty slick!
Thanks,
Eric
Hey, that's pretty slick!
Thanks,
Eric
Dim DelphiStringHex As String
Dim x As Integer
For x = 1 To Len(DelphiString - 1)
DelphiStringHex = DelphiStringHex & Hex(Asc(DelphiString.Subst
Next
MsgBox(DelphiStringHex)