网络序与主机序

以前只是了解,第一次遇到是在as400上。

说关键点:

  1) 网络序,也叫大端序

  2) 主机序,小端序

  3)相关api的转换,参考这个小哥的 https://blog.csdn.net/K346K346/article/details/79053136

  4)如何去判断本机是大小端

  

int GetLocalByteOrder()
{
    uint32_t                uiInt               = 0x01;

    return ((0x01 == *(unsigned char*)&uiInt) ? 0 : 1);
}

  5) 举例

  32位存放0x123456, 假设内存是0x01~0x31,在端的机器上

  ADDR:  0    7    15    23    31

  大端   00    12    34    56

  小端      56     34      12     00 

  6) 其它待补充

猜你喜欢

转载自www.cnblogs.com/ashen/p/10760963.html