Hello,
I am trying to read exact 2 bytes from binary file, and transfer it to int, whatever is it 2 or 4 bytes. Atm on my computer is 4 bytes. So I have two bytes into four bytes scenario. I am using this code
ifstream in_stream;
in_stream.open("test.dat", ios::binary);
streamoff offset = 0x4E00;
in_stream.seekg(offset);
int number1;
char buffer[2];
in_stream.read((char*)&buffer, 2);
number1= buffer[0]+ (buffer[1]<<8);
cout << number1 <<endl;
in_stream.seekg(offset);
short number2;
in_stream.read((char *)&number2, 2);
cout << number2;
but I can't get it why I get different number2 and number1 output? Not on every input are they different, but on some they are, and I can't notice pattern on which they are different. Any hints, help? Thanks in advance