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.

Big-endian and little-endian_第1张图片

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



你可能感兴趣的:(NetWork)