cpu大小端测试
来源:互联网 发布:淘宝怎么上架宝贝教程 编辑:程序博客网 时间:2024/06/05 14:07
关于cpu大小端中int或short的存放顺序,以及大小端序到网络序的转换
测试如下:
#include <stdio.h>#include <arpa/inet.h>int main(){unsigned int a = 0x12345678;unsigned int b;unsigned char *c;unsigned char *d;b = ntohl(a);c = (unsigned char *)&a;d = (unsigned char *)&b;printf("a = 0x%x, b = 0x%x\n", a, b);printf("c0 = 0x%x, c1 = 0x%x, c2 = 0x%x, c3 = 0x%x\n", c[0],c[1],c[2],c[3]);printf("d0 = 0x%x, d1 = 0x%x, d2 = 0x%x, d3 = 0x%x\n", d[0],d[1],d[2],d[3]);return 0;}
大端mips
a = 0x12345678, b = 0x12345678
c0 = 0x12, c1 = 0x34, c2 = 0x56, c3 =0x78
d0 = 0x12, d1 = 0x34, d2 = 0x56, d3 =0x78
由此,大端的高位在低地址,通过ntohl转换为网络字节序时数据没有变化
小端arm:
a = 0x12345678, b = 0x78563412
c0 = 0x78, c1 = 0x56, c2 = 0x34, c3 = 0x12
d0 = 0x12, d1 = 0x34, d2 = 0x56, d3 = 0x78
由此,小端的高位在低地址,通过ntohl转换为网络字节序时数据高低变换
也就是说,大端的系统上ntoh相关函数是不作处理的
小端的系统htoh相关函数会将高低位变换
0 0
- cpu大小端测试
- cpu大小端问题
- CPU大小端
- CPU大小端判断
- CPU大小端问题
- 判断CPU大小端
- cpu 大小端模式
- CPU大小端
- CPU大小端判断
- CPU大小端
- 判断cpu大小端
- 判断cpu大小端
- cpu 大小端检测
- 判断CPU大小端
- CPU大小端
- CPU大小端判定
- 判断CPU大小端模式
- 判断CPU的大小端
- 学习Spring cloud第二课(初识Spring cloud)
- 170314Css hacks
- mfcs80ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 已经定义 的 解决方法
- HDU2888
- CoreData之MagicalRecord源码解读
- cpu大小端测试
- Maven 运行异常
- Coursera--Big Data Analysis with Scala and Spark
- Activiti并行网关
- 信息安全上演“无间道” 京东、腾讯如何破解
- RPC 的概念模型与实现解析
- 《python数据挖掘入门与实践》笔记2
- 好记性不如烂笔头(jdk安装)
- TextView实现可复制,EditText实现不可编辑