I am trying to display the first two bytes of a binary file as a test. I have the following code.
void DisplayValuestext(){
Stream s = new FileStream("Assets//testbinary.bin", FileMode.Open);
BinaryReader br = new BinaryReader(s);
int dataVal = br.ReadUInt16();
Debug.Log(dataVal);
}
The first 2 bytes of the binary file are "1E44" which the function ReadUInt16() should read. However, it reads the first byte of data, "1E" rather then the first 2 bytes "1E44". I believe it is because it reads 2 characters, rather than 2 bytes. When I display the 16 bit unsigned integer "dataVal" in the console, I get 25905. The value I am trying to get is 17438 which is "1E44" little-endian encoded value converted to decimal.
I have also attempted to use the function "ReadUInt32". This method should read the first 4 bytes, however it instead displaces by 4 characters, which is 2 bytes "1E44". The console displays "875849009".
Why do I get these strange values "25905" and "875849009" and how can I resolve this to get the desired value of 17438?