您的位置:首页 > 其它

编写一个程序,判断系统是big endian,还是little endian

2016-04-14 14:47 525 查看
// Endian_1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

long ii = 0x123456;
long *pp=ⅈ

if(*pp==0x56){////低字节存放在低地址端,即是首地址
cout<<"system is little endian"<<endl;

}
else{
cout<<"system is big endian"<<endl;
}

long i = 0x123456;
long *p = &i;

if (*p==0x56)
{
printf("This is little endian system\n");
}
else
{
printf("This is big endian system\n");
}

system("pause");
return 0;
}

//system is big endian
//This is big endian system
//请按任意键继续. . .

JAVA字节序

BIG-ENDIAN、LITTLE-ENDIAN跟多字节类型的数据有关,比如int,short,long型,而对单字节数据byte却没有影响。BIG-ENDIAN就是低位字节排放在内存的高端,高位字节排放在内存的低端。而LITTLE-ENDIAN正好相反。

比如 int a = 0x05060708

在BIG-ENDIAN的情况下存放为:

           字节号 0 1 2 3     高地址端(高端)

高字节  数据 05 06 07 08   

在LITTLE-ENDIAN的情况下存放为:

字节号 0 1 2 3    高地址端(高端)

数据 08 07 06 05  高字节
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  little endian big