首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

检察你的机器是大端格式还是小端格式的C程序

2012-10-10 
检查你的机器是大端格式还是小端格式的C程序检查你的机器是大端格式还是小端格式的C程序?#include stdio.

检查你的机器是大端格式还是小端格式的C程序

检查你的机器是大端格式还是小端格式的C程序

?

#include <stdio.h>

union check

? ?{

? ? ? int high;

? ? ? char low;

? ?} test_ok;

int main(int argc,char *argv[])

{

? ?short test=0x0110;

? ?char *p=(char *)&test;

? ?if(p[0]==0x10)

? ?{

? ? ? //sm format

? ? ? printf("This arch is small format bits\n");

? ?}

? ?else

? ?{

? ? ? //big format?

? ? ? printf("This arch is big ?format bits\n");

? ?}

? ?printf("point address1=0x%.4x address2=0x%.4x\n",p[0],p[1]);

? ?test_ok.high=1;

? ?if(test_ok.low==1)

? ? {

? ? ?printf("Arch is small format\n");

? ? }

? ?else

? ?{

? ? ? printf("Arch is big format\n");

? ?}

? ?return 0;

}


热点排行