系统大小端测试程序
2015-06-17 12:56
281 查看
#include <stdio.h> #ifndef BOOL typedef enum BOOL_type {FALSE=0, TRUE=1} BOOL; #endif #ifndef uchar typedef unsigned char uchar; #endif #ifndef ushort typedef unsigned short int ushort; #endif BOOL isSmallEndianSys(void); void main(void) { printf("System Endian order test: %s Endian\n", isSmallEndianSys() ? "Small" : "Big"); } BOOL isSmallEndianSys(void) { union { uchar LowByte; ushort Short; } TestEndian; TestEndian.Short = 0x0001; return ((0x01 == TestEndian.LowByte) ? TRUE : FALSE); }
上述代码可能和网络上的一致或略有区别,为原创代码:
还有个超级精简版(我的原创):
#include <stdio.h> void main(void) { const unsigned short int num = 0x0001; printf("System Endian order test: %s Endian\n", *((unsigned char *) &num) ? "Small" : "Big"); }
转载请注明出处,谢谢!
相关文章推荐
- 总结近期所学的几种排序方法的基本思想
- 不能说的秘密:UEditor和UltraEdit
- Scrapinghub | Professional Services
- js查看对象内容
- 软件代码数字签名基本原理
- markdown常用格式一览
- 头部图片可伸缩的TableView
- Ubuntu下安装Mysql并使用
- 解决FLASH遮住层的问题 IE,Firefox都适用!
- myeclipse内存溢出
- IBM Juices Hadoop With Java On Tesla GPUs
- Error Correction
- atoi() & itoa()函数的内部的实现
- Linux开机自启动
- JDK自带VM分析工具jps,jstat,jmap,jconsole
- 云计算驱动智慧城市发展
- 【javaweb】左边选择右边展现的tld
- JAVA语法基础之函数的使用说明
- 精确度问题
- Linux命令查询