Hi, I am not exactly sure how to say this, but what I want to do is to write a series of strings converted to their hex notation to a binary file. Here is what I have:
Looking at a hex editor I see:Code:Dim hexNumbers As System.Text.StringBuilder = New System.Text.StringBuilder Private Sub add_byte(ByVal str As String) hexNumbers.Append(String.Format("{0:x}", Convert.ToChar(str))) End Sub Private Sub add_short(ByVal str As String) hexNumbers.Append(String.Format("{0:x}", Convert.ToInt16(str))) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fstream As New FileStream(Application.StartupPath & "\help.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite) Dim bw As BinaryWriter = New BinaryWriter(fstream) add_byte(DataGridView1.Rows(0).Cells(0).Value) add_byte(DataGridView1.Rows(0).Cells(1).Value) add_byte(DataGridView1.Rows(0).Cells(2).Value) add_byte(DataGridView1.Rows(0).Cells(3).Value) add_byte(DataGridView1.Rows(0).Cells(4).Value) add_short(DataGridView1.Rows(0).Cells(5).Value) add_short(DataGridView1.Rows(0).Cells(6).Value) bw.Write(String.Format("{0:x}", hexNumbers)) '<-- doesn't change a thing bw.Close() MsgBox("Done") End Sub
What I was going for was: 00 00 16 to be converted to 00 00 10 and have that value written to the binary file instead of the above 30 30 31 30.Code:30 30 31 30 0 0 1 0
So, what do I need to do to have the actual hex value written to the binary rather than it's ASCII equivalents?
Thanks




Reply With Quote