binary file reading
-
I was given a data file to read which is in binary format. I was told that the data starts in the file at position 0x1000. Each value following the offset is a 2byte short value. I tried reading in the file using fstream.ReadInt16(). It looks like some of the data is matching up correctly but the other isn't. Below on the left is what the data should be and on the right is what i'm getting 2 2 68 -188 -22 234 18 18 85 85 130 386 454 710 626 114 82 82 127 639 617 617 558 -210 As you can see some of it is matching up. Does anyone know what i'm doing wrong??
-
I was given a data file to read which is in binary format. I was told that the data starts in the file at position 0x1000. Each value following the offset is a 2byte short value. I tried reading in the file using fstream.ReadInt16(). It looks like some of the data is matching up correctly but the other isn't. Below on the left is what the data should be and on the right is what i'm getting 2 2 68 -188 -22 234 18 18 85 85 130 386 454 710 626 114 82 82 127 639 617 617 558 -210 As you can see some of it is matching up. Does anyone know what i'm doing wrong??
What is the content of the binary file for these numbers. Since the translation is out by either 0, 256, 512 or 768 in all cases it would suggest the binary format is not what you expect it. Windows expects LSB then MSB. It suggests that the binary file is MSB then LSB. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain) -
What is the content of the binary file for these numbers. Since the translation is out by either 0, 256, 512 or 768 in all cases it would suggest the binary format is not what you expect it. Windows expects LSB then MSB. It suggests that the binary file is MSB then LSB. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)The data is suppose to be x and y coordinates, so +/- integer values. I wasn't given any more information besides that. Is this a text encoding problem? Do you have any suggestions on how to test the LSB and MSB problem, I'm not very familiar with this or with binary file reading in general. thanks for the response
-
I was given a data file to read which is in binary format. I was told that the data starts in the file at position 0x1000. Each value following the offset is a 2byte short value. I tried reading in the file using fstream.ReadInt16(). It looks like some of the data is matching up correctly but the other isn't. Below on the left is what the data should be and on the right is what i'm getting 2 2 68 -188 -22 234 18 18 85 85 130 386 454 710 626 114 82 82 127 639 617 617 558 -210 As you can see some of it is matching up. Does anyone know what i'm doing wrong??
It looks, like after you read two bytes into buffer, you put a garbage in high byte, low byte is always correct: 68=0x0044, -188=0xff44 -22=0xffea, 234=0x00ea 130=0x0082, 386=0x0182 ... etc You have a bug somether in your program. Either two varables share the same memory, or you read just one byte and forget another, or....
-
The data is suppose to be x and y coordinates, so +/- integer values. I wasn't given any more information besides that. Is this a text encoding problem? Do you have any suggestions on how to test the LSB and MSB problem, I'm not very familiar with this or with binary file reading in general. thanks for the response
You may want to read up on Big Endian and Little Endian byte order for number representation. Intel Processors are Little Endian (PCs) Motorola Processors are Big Endian. Depending on how the file was created and on what operating system it could be stored either way. Little Endian is LSB then MSB. Big Endian is MSB then LSB. e.g. The hex value 0x7FFF when stored in: Little Endian = FF 7F Big Endian = 7F FF within the file. Note: Network packets have numbers stored in Big Endian no matter what OS originated them. I would suggest reading the raw data into a buffer then looking at the buffer contents (2-bytes at a time). You may be able to analyse why the numbers are not showing as you expect. Note: For a signed short(2-byte integer) the positive values will be 0x0000..0x7FFF and the negative values are 0x8000..0xFFFF. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)