首页 > 其他 > 详细

Big-endian and Little-endian

时间:2014-03-03 18:02:34      阅读:373      评论:0      收藏:0      [点我收藏+]

Big-endian is used in the network transmission, while Little-endian is popular in x-86 systems. Two pictures follow.

bubuko.com,布布扣bubuko.com,布布扣

Possible advantages for using differnt policies:

Big-endian: good for transmission

Little-endian: good for variable transformation, for example, char <--> short


Testing codes for the system:

#include <iostream>
using namespace std;

int main() {
	union checkit {
		char charword[4];
		unsigned int intword;
	} check;

	check.charword[0] = 1;
	check.charword[1] = 2;
	check.charword[2] = 3;
	check.charword[3] = 4;

	if (check.intword == 0x01020304) 
		cout<<"Big-endian";
	if (check.intword == 0x04030201) 
		cout<<"Little-endian";
	return 0;
}



Big-endian and Little-endian,布布扣,bubuko.com

Big-endian and Little-endian

原文:http://blog.csdn.net/jsc0218/article/details/20319353

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!