测试机器大小端
来源:互联网 发布:淘宝卖家开店流程2016 编辑:程序博客网 时间:2024/06/10 03:44
intel32的机器,虽然是64位的系统,
但,
short是2个字节啊。
大端:低地址取出来的是高位字节。这是网络字节序。
#include<stdio.h>#include<stdlib.h> void byteorder(){ union{ short value; char union_bytes[sizeof(short)]; }test; printf("sizeof(short) is [%d]\n",sizeof(short)); test.value=0x0102; if((test.union_bytes[0]==1) &&(test.union_bytes[1]==2)) { printf("big endian,高位字节存储在低地址,低位字节在高地址。\n"); }else if((test.union_bytes[0] ==2 ) && (test.union_bytes[1]==1)) { printf("little endian ,低位字节存放在内存的低地址,高位字节存放在内存的高地址 \n"); } else printf("UNKOWN\n"); // return 0;} int main() { byteorder(); system("pause"); return 0; }
=================================
后来读 http://www.adobe.com/cn/devnet/rtmp.html 的http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/rtmp/pdf/rtmp_specification_1.0.pdf时候:
All integer fields are carried in network byte order, byte zero is
the first byte shown, and bit zero is the most significant bit in a
word or field. This byte order is commonly known as big-endian.The
transmission order is described in detail in Internet Protocol
[RFC0791]. Unless otherwise noted, numeric constants in this
document are in decimal (base 10).
可见,无论大端小端,向内存存入数据,都是先内存低地址,然后高地址。
这样,大端存入的时候,是先把高位数据存入(也是从低地址开始存),那么低位地址就对应了高位数据,所以叫做大端了。
- 测试机器大小端
- 测试一个机器大小端
- 测试机器大小端的方法
- 测试机器大小端存储的方法
- 测试机器大小端字节序的小程序
- C语言测试机器大小端字节序
- MATLAB测试机器零阈值的大小
- 机器大小端判断
- 机器的大小端
- 判断机器大小端
- 经典笔试题:用C写一个函数测试当前机器大小端模式
- 判断机器大小端问题
- 判断机器的大小端
- 大小端机器的判定
- 机器大小端的检测
- 机器大小端的检测
- 判断机器的大小端
- 机器大小端存储问题
- 完美实现Silverlight动态加载
- Oracle基础知识(十三) - 层次查询
- 实现atoi() 测试页面如下
- 直接拿来用!最火的Android开源项目(一)
- 分解大量switch-case分支的两种方法
- 测试机器大小端
- PB数据窗口大量数据更新速度慢的问题
- LINUX 环境变量
- MapReduce编程实例(三)
- Android开发之资源文件存储
- No Java compiler available异常
- table铺满全屏
- 正则表达式校验及实例
- Java程序基本优化