Yes, I have read solutions for about 5 hours, none of them work.
BitConverter just creates a blank string.
Basically what I’m doing is trying to create a level reader, which will read a levels contents via hex and eventually display it in a treeview. So the first thing I have to do is make a byte array in which I can edit the data, I’ve done that.
However, now I want to display the data on the screen. To my knowledge you can’t display a byte array on screen, you must first convert it to a string.
So that’s what I’m trying to do:
using (OpenFileDialog fileDialog = new OpenFileDialog())
{
if (fileDialog.ShowDialog() != DialogResult.Cancel)
{
textBox1.Text = fileDialog.FileName;
using (BinaryReader fileBytes = new BinaryReader(new MemoryStream(File.ReadAllBytes(textBox1.Text))))
{
string s = null;
int length = (int)fileBytes.BaseStream.Length;
byte[] hex = fileBytes.ReadBytes(length);
File.WriteAllBytes(@"c:\temp_file.txt", hex);
}
}
}
}
Note: i have removed my conversion attempts as nothing I have tried worked.
Does anyone know how I could use this data and convert it to a string, and add it to a textbox? (I know how to do the latter, of course. It’s the former that I’m having difficulties with.)
If so, please provide examples.
I probably should have made myself more clear; I don’t want to convert the byte to the corresponding character (i.e. if It is 0x43, I DON’T want to print ‘C’. I want to print ’43’.
Do you know in which encoding your byte array is stored?
You need Encoding.GetString method
Here is MSDN example
EDIT
If you want to print out byte array in hex format, BitConverter is what you are looking form, here is MSDN example