On 7/11/05, Robert P. J. Day <[EMAIL PROTECTED]> wrote:
>
> is there a standard set of byte swap macros/functions for doing
> big/little endian conversion? i have no interest in re-inventing the
> wheel and i'm sure there's a universally-recognized set of macros for
> this, no?
>
For quick and dirty solutions I sometimes use one of the following
(not favoured over any other solution, it just work for me):
#define swap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
#define swap_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
uint64_t swap_64(uint64_t x) {
union {
uint64_t ll;
uint32_t l[2];
} w, r;
w.ll = x;
r.l[0] = bswap_32 (w.l[1]);
r.l[1] = bswap_32 (w.l[0]);
return r.ll;
}
Kind Regards
\Steve
--
Steve Graegert <[EMAIL PROTECTED]> || <http://www.technologies.de/~sg/>
Independent Software Consultant {C/C++ && Java && .NET}
Mobile: +49 (176) 21 24 88 69
Office: +49 (9131) 71 26 40 9
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming"
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html