|
ActiveSocket Network Communication Toolkit - SNMP Get/GetNext/Set and SNMP Traps using Visual Basic .NET, Visual Studio .NET, ASP, ASP.NET, PHP, Delphi, ColdFusion and more
|
Visit ActiveSocket Web Site
Download ActiveSocket Network Communication Toolkit
Big Endian - an explanation
A format for the storage or transmission of data that places the most significant byte (or bit) first.Endianness is the attribute of a system that indicates whether integers are represented from left to right or right to left. Why, in today's world of virtual machines and gigahertz processors, would a programmer care about such a silly topic? Well, unfortunately, endianness must be chosen every time a hardware or software architecture is designed, and there isn't much in the way of natural law to help decide. So implementations vary.
Endianness comes in two varieties: big and little. A big-endian representation has a multibyte integer written with its most significant byte on the left; a number represented thus is easily read by English-speaking humans. A little-endian representation, on the other hand, places the most significant byte on the right. Of course, computer architectures don't have an intrinsic "left" or "right" about them. These human terms are borrowed from our written forms of human communication. The following definitions are more precise:
- Big endian means that the most significant byte of any multibyte data field is stored at the lowest memory address, which is also the address of the larger field.
- Little endian means that the least significant byte of any multibyte data field is stored at the lowest memory address, which is also the address of the larger field.
All processors must be designated as either big endian or little endian. Intel's 80x86 processors and their clones are little endian. Sun's SPARC, Motorola's 68K, and the PowerPC families are all big endian. The Java Virtual Machine is big endian as well. Some processors even have a bit in a register that allows the programmer to select the desired endianness.
An endianness difference can cause problems if a computer unknowingly tries to read binary data written in the opposite format from a shared memory location or file. Take a look at an 80x86 memory dump with a 16- or 32-bit integer stored inside, such as that shown in Figure 1. An 80x86 processor stores data in memory with its least significant byte first. However, your mind tends to expect the data to read from the most significant byte to the least.
|