Big Endian and Little Endian order refer to the ordering of bytes in word and double word values by different processors. Intel processors use little endian order and Motorola use big endian.

Normally byte ordering does not concern the programmer, we use one scheme or the other depending on our target platform, but, while writing my TIFF and PNG image loaders I needed to be able to convert between the different ordering schemes. I came up with these macros to convert between formats:


#define FlipWord(w) ( w<<8 | w>>8 )
#define FlipDword(d) (d<<24 | ((d<<8) & 0xFF00) | ((d>>8) & 0xFF0000) | d>>24)
 


 
The term 'Endian' is derived from Jonathan Swift's book, 'Gulliver's Travels'. In the book, the empires of Lilliput and Blefuscu are at war over which end of an egg should be cracked for eating. The big endians believe the large end of the egg should be used, as opposed to the little endians who belive that the big end is dangerous as the Emperor once cut his finger on it.
Thus the 'Holy War' between endian camps extends into the present day and gives us problems with processor architecture, Swift would be proud. :o)

Codehead - 21/06/03

Problems, ideas, better routines ?
Mail me or drop into the forums


Home EMail Forum