Problem that I am having is :
I am reading a array of bytes using binary reader to construct a windows gui for editing of a file, for instance I am reading the following byte array: 123cbb75
//read the first 4 bytes from 0x36A2
byte[] buffer = br.ReadBytes(4);
Array.Reverse(buffer);
Encoding enc8 = Encoding.UTF8;
data = enc8.GetString(buffer);
data = (BitConverter.ToInt32(buffer, 0).ToString("X8"));
textBox1.Text = data; //reads the full string of hex
//values 123CBB75-- first 4 bytes
textBox2.Text = data.Substring(0, 2);//reads 12
textBox3.Text = data.Substring(2, 1);//reads 3
textBox4.Text = data.Substring(3 ,1);//reads C
textBox5.Text = data.Substring(4, 1);//reads B
textBox6.Text = data.Substring(5, 1);//reads B
textBox7.Text = data.Substring(6, 1);//reads 7
textBox8.Text = data.Substring(7, 1);//reads 5
br.Dispose();
I can easily edit the first byte because it has a two integer representation
using Convert.ToByte
(to edit a string from a text box and write it back into the binary file)
Question is : How do I edit the singular values from the text box so then it can write the value correctly back using binarywriter such as from textbox 3 or 4. I cannot use Convert.ToByte
because its a singular numerical or alphabetical figure.
bw.Write(Convert.ToByte(textBox3.Text, 16)); //output
is not correct when writing the data back to the file, if I want to change 3 to 5.