当前位置:编程学习 > C/C++ >>

64位网络字节序与主机字节序转换

 

unsigned long long ntohll(unsigned long long val)
  {
     if (__BYTE_ORDER == __LITTLE_ENDIAN)
      {
         return (((unsigned long long )htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32));
     }
     else if (__BYTE_ORDER == __BIG_ENDIAN)
      {
         return val;
     }
 }
 
 unsigned long long htonll(unsigned long long val)
  {
     if (__BYTE_ORDER == __LITTLE_ENDIAN)
      {
         return (((unsigned long long )htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32));
     }
     else if (__BYTE_ORDER == __BIG_ENDIAN)
      {
         return val;  www.zzzyk.com
     }
 }


作者: MrRightLeft
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,