write a macro to judge big endian or little endian
Big endian means the most significant byte stores first in memory. int a=0x01020304, if the cpu is big endian, data are store 01 02 03 04 in memory in increasing address.
Below is a simple code to make the judgement.
//execute the following cmd on the command line,
//Judge the output, 1 for little endian, 0 for big endian
//echo -n I | od -o | head -n 1 | cut -f2 -d " " | cut -c 6
//1
#include <stdio.h>
#define IS_BIG_ENDIAN (*(short*)"\0\1" == (short)1)
int main()
{
if (IS_BIG_ENDIAN)
printf("the cpu is big endian\n");
else
printf("the cpu is small endian\n");
}
write a macro to judge big endian or little endian的更多相关文章
- c#,关于Big Endian 和 Little Endian,以及转换类
Big Endian:最高字节在地址最低位,最低字节在地址最高位,依次排列. Little Endian:最低字节在最低位,最高字节在最高位,反序排列. 当在本地主机上,无需注意机器用的是Big En ...
- 字符编码笔记:ASCII,Unicode和UTF-8,附带 Little endian和Big endian的解释
作者: 阮一峰 日期: 2007年10月28日 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直看到晚上9点,才算初步 ...
- Endian.BIG_ENDIAN和Endian.LITTLE_ENDIAN(http://smartblack.iteye.com/blog/1129097)
Endian.BIG_ENDIAN和Endian.LITTLE_ENDIAN 在ByteArray和Socket中,能看到一个属性endain. endian : String 更改或读取数据的字节顺 ...
- 大endian和little endian
大endian和little endian 一般Intel处理器或X86平台是小端 ,只是有点老了摩托罗拉的处理器将采用大端,掌握一下小端序. 小端序一般指低地址存低字节.高地址存高 ...
- Big Endian与Litter Endian
Big Endian是大端,Litter Endian是小端,意思很明了,但是很难记住谁是谁.每次涉及到这个概念的时候,我都会GOOGLE一下,浪费精力. 怎样才能永远记住他们呢?网上搜索了一下,有很 ...
- 数据在内存中的存储方式( Big Endian和Little Endian的区别 )(x86系列则采用little endian方式存储数据)
https://www.cnblogs.com/renyuan/archive/2013/05/26/3099766.html 1.故事的起源 “endian”这个词出自<格列佛游记>.小 ...
- 关于Big Endian 和 Little Endian
Big Endian 和 Little Endian 一.字节序 来自:http://ayazh.gjjblog.com/archives/1058846/ 谈到字节序的问题,必然牵涉到两大CPU派系 ...
- java代码中存在的Big Endian 和 Little Endian
Big Endian 和 Little Endian 详解 Java中的Big(Little)-endian问题的一种解决方法 主机序和网络序 很重要很重要 几种ip存放形式 Big-Endian和 ...
- 大端和小端(Big endian and Little endian)
一.大端和小端的问题 对于整型.长整型等数据类型,Big endian 认为第一个字节是最高位字节(按照从低地址到高地址的顺序存放数据的高位字节到低位字节):而 Little endian 则相反,它 ...
- 大端和小端(big endian little endian)
一.大端和小端的问题 对于整型.长整型等数据类型,Big endian 认为第一个字节是最高位字节(按照从低地址到高地址的顺序存放数据的高位字节到低位字节):而 Little endian 则相反,它 ...
随机推荐
- Java基础加强学习笔记(二)
一.反射的基础Class类 1.如何得到各个字节码对应的实例对象 (1)类名.class,例如 System.class (2)对象.getClass(),例如 new Data().getClass ...
- json与jsonp ajax
今天在网上找了一下资料,发现这篇文章总结得好,果断转了:http://blog.csdn.net/superhosts/article/details/9057301
- Linux中.a,.la,.o,.so文件的意义和编程实现
Linux中.a,.la,.o,.so文件的意义和编程实现 Linux下文件的类型是不依赖于其后缀名的,但一般来讲: .o,是目标文件,相当于windows中的.obj文件 ...
- http协议使用实例
#include <stdio.h>#include <windows.h>#include <wininet.h> #define MAXSIZE 1024#pr ...
- leetcode-Rising Temperature
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
- zabbix linux被监控端部署
测试使用agentd监听获取数据. 服务端的安装可以查看http://blog.chinaunix.net/space.php?uid=25266990&do=blog&id=3380 ...
- 如何从google play下载app应用,直接下载apk
如何从google play直接下载apk by fly2004jun 2013-10-05 转载请附出处 由于某些原因,大天朝局域网访问google很多服务不能用,其中就包括google ...
- POJ 2886 Who Gets the Most Candies? 线段树。。还有方向感
这道题不仅仅是在考察线段树,还他妹的在考察一个人的方向感.... 和线段树有关的那几个函数写了一遍就对了,连改都没改,一直在转圈的问题的出错.... 题意:从第K个同学开始,若K的数字为正 则往右转, ...
- JS-Date日期内置对象
1.基本用法 <script> var date = new Date(); document.write(date+"<br/>");//获取具体时间 d ...
- [Polymer] Custom Elements: Styling
Code: <dom-module id="business-card"> <template> <div class="card" ...