Hello.
I have managed to read a binary file, and have put the data in a "unsigned char" array.
The problem is that "unsigned char" is 1 byte large, but I need the data to be stored in a 2 byte large "short" array, because the data is a 16 bit value, being used to create picture data.
I have made some attempts on this, but I am unsure if it works.
This is my code so far:
unsigned char imagebuffer[4096];
short *Shortbuffer;
Imagery = Ptr;// Ptr points to a place in a large "unsigned char" buffer.
// This loop takes the first 4096 bytes of this buffer and places it
//in it's own temporary buffer.
for(int i=0; i<4096; i++)
{
imagebuffer[i] = buffer[(*Imagery+i)];
}
//The next thing I am trying to do is to convert this
//temporary "unsigned buffer into a "short".
Shortbuffer = (reinterpret_cast<short *> imagebuffer));
My problem is that I don't know how to check if the data in the shortbuffer is now correct. As I understand it, shortbuffer is a pointer that points to"(reinterpret_cast<short *> imagebuffer));".
But, I want the shortbuffer data to be placed in an array of it's own. (Finalshortbuffer[2048]).
So my questions are then:
1: will the "reinterpret_cast<short *> imagebuffer" convert the unsigned char into a short?
2: If so how do I put the data into it's own array?
Hope for an informativ answer.
Kristian