Penguin
Note: You are viewing an old revision of this page. View the current version.

The order of bytes stored/sent in a computer. For example if the number 0x01020304 is sent as the 4 bytes "01 02 03 04" then it is BigEndian. If it's sent as "04 03 02 01" then it is LittleEndian.

There is also the somewhat bizzare PDP-endian "02 01 04 03" - probably due to an attempt at backwards compatibility in the transition from 1-byte to 2-byte integers, and no such attempt from 2-byte to 4-byte integers. (A little googling will probably discover the reason for this endian-ness.)

NetworkByteOrder is usually BigEndian, and HostByteOrder? is LittleEndian for Intels (Although almost everyone else is BigEndian these days).

Big-endian systems: SGI Irix (MIPS CPU) and Indys, IBM RS6000 & Apple Powermac (Power/PowerPC), SUN (Sparc)

little-endian systems: (DEC Alpha, Intel x86 & compatibles like AMD)

Humans are "BigEndian", we write numbers as "1234" not "4321"


C program to demonstrate this

$ cat > x.c

  1. include <stdio.h>
  2. include <fcntl.h>

int main() {

int x=0xaabbccdd; int fd=open("/tmp/output", O_CREAT|O_EXCL|O_WRONLY, 0644); return write(fd, &x, sizeof(int));

}

$ gcc -o x x.c $ ./x $ od -t x1 /tmp/output 0000000 dd cc bb aa 0000004

This shows that (on an x86 system) the bytes "aa bb cc dd" were stored as "dd cc bb aa".

Doing the same thing on a SPARC gives the (more intuitive)
$ od -t x1 /tmp/output 0000000 aa bb cc dd 0000004