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:
Expand|Select|Wrap|Line Numbers
- 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.