Hi.
I am having some problem converting some signed shorts from little endian (intel) to big (motorola chip).
Im using this code but it appear to produce errors when I convert some negative shorts:
Eg when I convert values near 0, -256, -512, -756 I get converted values around +2500, +2800, etc. Note these values are approximate ie I have an idea of where the problems are occuring but not the exact values.
I think it has something to do with the sign bit. Can anyone suggest a modification to my code to solve this problem?
thanks in advance.
I am having some problem converting some signed shorts from little endian (intel) to big (motorola chip).
Im using this code but it appear to produce errors when I convert some negative shorts:
Code:
short SwapShortWords( const short sWord )
{
union {
short iSwapped;
char acBytes[2];
}
WordIn, WordOut;
WordIn.iSwapped = sWord;
WordOut.acBytes[0] = WordIn.acBytes[1];
WordOut.acBytes[1] = WordIn.acBytes[0];
return WordOut.iSwapped;
}
I think it has something to do with the sign bit. Can anyone suggest a modification to my code to solve this problem?
thanks in advance.
Comment