/* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file lib/src/swap.c * \brief generic swap functions * \ingroup lib */ #include "common/std.h" #include "lib/swap.h" /** swap an unsigned short */ u16 swap16(u16 x) { return (u16)( (((u16)(x) & (u16)0x00ff) << 8) | (((u16)(x) & (u16)0xff00) >> 8) ); } /** swap an unsigned long */ u32 swap32(u32 x) { return (u32)( (((u32)(x) & (u32)0x000000ff) << 24) | (((u32)(x) & (u32)0x0000ff00) << 8) | (((u32)(x) & (u32)0x00ff0000) >> 8) | (((u32)(x) & (u32)0xff000000) >> 24) ); }