bswap.c revision 38451
1/* 2 * Written by Manuel Bouyer <bouyer@netbsd.org>. 3 * Public domain. 4 */ 5 6#if defined(LIBC_SCCS) && !defined(lint) 7static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $"; 8static char *rcsid = "$NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $"; 9#endif 10 11#include <sys/types.h> 12 13#undef bswap32 14#undef bswap64 15 16u_int32_t 17bswap32(x) 18 u_int32_t x; 19{ 20 return ((x << 24) & 0xff000000 ) | 21 ((x << 8) & 0x00ff0000 ) | 22 ((x >> 8) & 0x0000ff00 ) | 23 ((x >> 24) & 0x000000ff ); 24} 25 26u_int64_t 27bswap64(x) 28 u_int64_t x; 29{ 30 u_int32_t *p = (u_int32_t*)&x; 31 u_int32_t t; 32 t = bswap32(p[0]); 33 p[0] = bswap32(p[1]); 34 p[1] = t; 35 return x; 36} 37 38