#define HOST_LITTLE_ENDIAN
typedef unsigned short int UINT16;
typedef unsigned long int UINT32;
typedef unsigned long long int UINT64;
#ifdef HOST_LITTLE_ENDIAN
#define XY_SWAP_16(s) ((((UINT16)(s) & 0xff00) >> 8) | (((UINT16)(s) & 0x00ff) << 8))
#define XY_SWAP_32(l) ((((UINT32)(l) & 0xff000000) >> 24) | \
(((UINT32)(l) & 0x00ff0000) >> 8) | \
(((UINT32)(l) & 0x0000ff00) << 8) | \
(((UINT32)(l) & 0x000000ff) << 24))
#define XY_SWAP_64(ll) (((UINT64)(ll) >> 56) |\
(((UINT64)(ll) & 0x00ff000000000000) >> 40) |\
(((UINT64)(ll) & 0x0000ff0000000000) >> 24) |\
(((UINT64)(ll) & 0x000000ff00000000) >> 8) |\
(((UINT64)(ll) & 0x00000000ff000000) << 8) |\
(((UINT64)(ll) & 0x0000000000ff0000) << 24) |\
(((UINT64)(ll) & 0x000000000000ff00) << 40) |\
(((UINT64)(ll) << 56)))
#define SWAP_NTOH(x) if (2 == sizeof(x)){(x) = XY_SWAP_16(x);}\
else if (4 == sizeof(x)){(x) = XY_SWAP_32(x);}\
else if (8 == sizeof(x)){(x) = XY_SWAP_64(x);}\
else {printf("ERR: SWAP_BYTE_ORDER %s,%d\n", __FUNCTION__, __LINE__);}
#define SWAP_HTON(x) SWAP_NTOH(x)
#else
#define XY_SWAP_16(s) (s)
#define XY_SWAP_32(l) (l)
#define XY_SWAP_64(ll) (ll)
#define SWAP_NTOH(x) (x)
#define SWAP_HTON(x) SWAP_NTOH(x)
#endif
int main()
{
UINT32 tmpl = 0x12345678;
UINT64 tmpll = 0x1234567887654321;
printf("tmpl is 0x%x\n", tmpl);
SWAP_HTON(tmpl);
printf("tmpl is 0x%x\n", tmpl);
printf("tmpll is 0x%llx\n", tmpll);
SWAP_HTON(tmpll);
printf("tmpll is 0x%llx\n", tmpll);
printf("Hello world!\n");
return 0;
}