Is there any way to convert a Byte into a int8? I have been given a binary file that contains a list of input parameters for a test. The parameters vary in size from uint32 down to uint8. I am having no problem reading in the file, what is tricky is getting the values to display in the GUI.
Here's is the basis of what I'm doing:
private Byte blockSize;
private Byte binSize;
FileStream filen = File.OpenRead(file);
BinaryReader br = new BinaryReader(filen);
blockSize = br.ReadBytes(4);
binSize = br.ReadBytes(1);
textBox1.Text = BitConverter.ToInt32(blockSize, 0).ToString();
textBox2.Text = BitConverter.ToString(binSize, 0).ToString();
Your problem that
byte then your call
BitConverter.ToString(bytearray) with byte array as parameter which do the next:
Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation
BinaryReader has methods
int ReadInt32() byte ReadByte()
Change types of
byte and use those methods
int blockSize = br.ReadInt32(); byte binSize = br.ReadByte(); textBox1.Text = blockSize.ToString(); textBox2.Text = binSize.ToString();
Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.
Reads the next byte from the current stream and advances the current position of the stream by one byte.