Original Post
I found that the jpeg format was a big endian format, so to read it I needed to write a couple of small functions that would swap the bytes in a variable. I was having problems with this until about 5 minutes ago. Previously, the last line was "s |= b1;", which I thought would work fine. But, I had a value 0x8400, which after being swapped became 0xff84. Where would it get the 0xff for the upper byte? Would it transfer OR the short with 2 bytes worth of b1, regardless of the fact that it's a single byte char? Edit:: oh, and just for the sake of writing proper code, should the second-to-last line be "s |= (b0 << 8) & 0xff00; ?"
/**
* Swap the bytes in the var
* \param s A reference to the var to swap the bytes
*/
void swapBytes(short& s)
{
char b0 = s & 0xff; // lower byte
char b1 = (s & 0xff00) >> 8; // upper byte
s = 0;
s |= b0 << 8; // set lower byte to upper byte
s |= (b1 & 0xff); // set upper byte to lower byte
}