RE: [Algorithms] Byte Swapping
Brought to you by:
vexxed72
From: Eugene F. <fo...@dr...> - 2000-07-20 00:32:09
|
If you're writing to the Mac (or even just have the QuickTime SDK installed), there are some handy endian-swapping macros in Endian.h. They're of the form (using unsigned longs as an example) EndianU32_?to?(value) where the characters in the question marks are L (for little endian), B (for big endian), and N (for native format). Thus, since your data files are in big endian format you could write EndianU32_BtoN(value) which would do a conversion when compiled for Intel and compile to nothing for PPC. Endian.h uses ConditionalMacros.h to figure out whether you're compiling for big or little endian. The only problem is that they don't automatically use CodeWarrior's intrinsic functions mentioned earlier by Jens Ayton. I've found that CodeWarrior lets me get away with the following code, which is in my precompiled header: #include <Endian.h> #undef Endian32_Swap #define Endian32_Swap(value) \ ( *(uint32*)&(value) = __lwbrx( (uint32*)&(value), 0 ) ) #undef Endian16_Swap #define Endian16_Swap(value) \ ( (value) = __lhbrx( &(value), 0 ) ) -----Original Message----- From: gda...@li... [mailto:gda...@li...]On Behalf Of Michael S. Harrison Sent: Tuesday, July 18, 2000 5:30 AM To: gda...@li... Subject: Re: [Algorithms] Byte Swapping hehe. True. That comment reflects the fact that all of our basic data files are in Motorola format and have to be converted when running on the PC At 10:48 AM 7/18/00, you wrote: ----- Original Message ----- From: Michael S. Harrison To: gda...@li... Sent: Tuesday, July 18, 2000 1:17 AM Subject: Re: [Algorithms] Byte Swapping [ SNIP ] /* these assume that the swapping is from motorola to intel format */ [ SNIP ] ...or vice versa ;-)))) Are, F |