November 18th, 2012, 03:45 PM
Convert 2-byte array to short int
I'm having trouble reading a block of bytes into a vector of short ints. My code is as follows:
The relevant block of data starts at offset 2821 in the file. Every two bytes are a signed short integer. What's odd is that it's giving me the correct results only part of the time. At offset 1052421 and 1052422 there are two bytes 40 and 1F that are correctly read in as 8000, but at offset 1052415 and 1052416 bytes 88 and 13 are read in as -120 instead of 5000.
int iter = 0;
g_Data[iter] = (shortBuf << 8) | shortBuf;
I don't see anything wrong with my code, though, unless I'm misunderstanding completely how to convert an array of two bytes into a single float. Is my method correct? Better still, is there some way to just convert en mass an array of bytes into a vector of signed short ints?
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.