大端小端的概念
2016-03-06 21:47
218 查看
对于一个由2个字节组成的16位整数,在内存中存储这两个字节有两种方法:一种是将低序字节存储在起始地址,这称为小端(little-endian)字节序;另一种方法是将高序字节存储在起始地址,这称为大端(big-endian)字节序。术语“小端”和“大端”表示多个字节值的哪一端(小端或大端)存储在该值的起始地址。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
int main()
{
union
{
short s;
char c[sizeof(short)];
} un;
un.s = 0x0102;
if (sizeof(short) == 2)
{
if (un.c[0] == 1 && un.c[1] == 2)
printf("big-endian\n");
else if (un.c[0] == 2 && un.c[1] == 1)
printf("little-endian\n");
else
printf("unknown\n");
}
else
printf("sizeof(short)= %d\n", sizeof(short));
//exit(0);
system("pause");
}
以上是一个检测大端小端的程序。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
int main()
{
union
{
short s;
char c[sizeof(short)];
} un;
un.s = 0x0102;
if (sizeof(short) == 2)
{
if (un.c[0] == 1 && un.c[1] == 2)
printf("big-endian\n");
else if (un.c[0] == 2 && un.c[1] == 1)
printf("little-endian\n");
else
printf("unknown\n");
}
else
printf("sizeof(short)= %d\n", sizeof(short));
//exit(0);
system("pause");
}
以上是一个检测大端小端的程序。
相关文章推荐
- Ruby中require、load、include、extend的区别介绍
- vbscript include的办法实现代码第1/2页
- 解析C++编程中的#include和条件编译
- PHP脚本中include文件出错解决方法
- Flex include和import ActionScript代码
- set_include_path在win和linux下的区别
- php include加载文件两种方式效率比较
- How to Auto Include a Javascript File
- 浅谈ASP.NET的include的使用方法
- java/jsp中 中文问题详解
- php相对当前文件include其它文件的方法
- JSP计数器的制作
- php include和require的区别深入解析
- PHP include_path设置技巧分享
- JS 实现完美include载入实现代码
- JS实现完美include加载功能代码
- JSP开发入门(四)--JSP的内部对象
- 实战 J2EE 开发购物网站 二
- php 中include()与require()的对比
- JSP中include指令和include行为的区别