C (41/254)

From:Duane McDonnell
Date:01 Apr 00 at 09:44:10
Subject:Re: endian code donations?

>If you have an int, you can do it like this, although this looks real nasty
>and
>there must be an easier way to do it (its only three instructions in ASM):

>int endian;/* value you want to swap between formats */
>int swapped;/* value after swap */

>swapped = (((unsigned int)endian & 0xFF) << 24) |
> (((unsigned int)endian & 0xFF00) << 8) |
> (((unsigned int)endian & 0xFF0000) >> 8) |
> (((unsigned int)endian & 0xFF000000) >> 24);

I believe this is the optimal way to do this in portable C. If
portability isn't an issue you can inline/emit the ROL.W/SWAP/ROL.W
sequence. If you're a SAS/C user you can also use __builtin_rol
or __builtin_ror.

------------------------------------------------------------------------
PERFORM CPR ON YOUR APR!
Get a NextCard Visa, in 30 seconds! Get rates as low as
0.0% Intro or 9.9% Fixed APR and no hidden fees.
Apply NOW!
http://click.egroups.com/1/2121/1/_/451227/_/954592536/
------------------------------------------------------------------------