Big-endian and little-endian

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


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;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章