int64 字节序转换

主机字节序与网络字节序之间的转换:

#ifndef WIN32

typedef long long __int64;

#endif

__int64 hton64(__int64 val ) 

long high, low;
low = (long)(val & 0x00000000FFFFFFFF);
val>>=32;
high = (long)(val & 0x00000000FFFFFFFF);
low = htonl( low );
high = htonl( high );


__int64 nRet = 0;
nRet = low;
nRet <<=32;
nRet |= high;


return nRet; 



__int64 ntoh64(__int64 val )
{
long high, low;
low = (long)(val & 0x00000000FFFFFFFF);
val>>=32;
high = (long)(val & 0x00000000FFFFFFFF);
low = ntohl( low );
high = ntohl( high );


__int64 nRet = 0;
nRet = low;
nRet <<=32;
nRet |= high;


return nRet;
}

你可能感兴趣的:(int64 字节序转换)