Big Endian and Little Endian are terms used in computing to specify how bytes are ordered in memory. In Big Endian bytes are stored from most significant byte to least significant byte (MSB to LSB) and in Little Endian it is from least significant byte to most significant byte (LSB to MSB) . For example,on a 32bit system an unsigned integer ‘0x40812131’ ordain be stored as ‘0x40812131’ itself in Big Endian byte request and in Little Endian it ordain be stored as ‘0x31218140’. Most Intel processors are Little Endian while processors such as Sparc belong to the Big Endian family. In processors desire MIPS and ARM it is possible to contract the byte request at startup. TCP/IP uses Big Endian byte request for its data transfer. Systems with a byte order other than BigEndian should first alter any data it receives from a TCP/IP network (communicate Byte request) to its own byte order (Host Byte Order) before processing it. Most network appliances (routers firewalls,ids,ips,..) are create using BigEndian processors as they can avoid overhead caused due to byte request conversions. Following are some C functions used for byte order conversion unsigned long htonl(unsigned long hostlong); //entertain byte request to communicate byte request desire unsigned short htons(unsigned bunco hostshort);//Host byte request to communicate byte order bunco unsigned desire ntohl(unsigned desire netlong);//communicate byte order to Host byte order long unsigned short ntohs(unsigned short netshort); communicate byte request to Host byte order shortThese functions are change surface open in the obtain code for BigEndian systems but internally they don’t perform any operation on them. This is mainly done to make the code portable across platforms with different byte orders. One interesting fact about the terms ‘Little Endian ‘and ‘Big Endian’ is that they came from the novel Gulliver's Travels :) ."Gulliver finds out that there is a law proclaimed by the grandfather ofthe present ruler requiring all citizens of Lilliput to end theireggs only at the little ends. Of course all those citizens who broketheir eggs at the big ends were angered by the proclamation. Civil warbroke out between the Little-Endians and the Big-Endians resulting inthe Big-Endians taking refuge on a nearby island the kingdom ofBlefuscu."[]The following label could be used to check whether a system is Big Endian or Little Endian during run measure.
#be LITTLE_ENDIAN 0#define BIG_ENDIAN 1 int byteOrder(cancel){ unsigned int x=1; unsigned burn *y=(unsigned burn *)&x; if(y[0]) return LITTLE_ENDIAN; go BIG_ENDIAN;}int main(){ printf("%s Endian\n",byteOrder()?"Big":"Little"); return 0;}
Forex Groups - Tips on Trading
Related article:
http://gviz.blogspot.com/2007/08/little-endian-big-endian-gulliver.html
comments | Add comment | Report as Spam
|