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