Monday, July 11, 2005

Real World Endianess Example

With gasoline being a commodity, my brand loyalty is non-existent. Whichever station has the lowest price gets my dollar (or actually, as of this morning, my $2.34 per gallon). Oh, and the gas station MUST have pay-at-the-pump, else I don't patronize them.

One itsy-bitsy problem with bouncing between different gas stations and using pay-at-the-pump is that you have to figure out which direction to swipe your credit card in order for the pump to read it.

Sometimes, the stripe has to go to the left, sometimes to the right, and some pumps have cool readers that can read the card in either direction. I find that I always have to look at the little picture on the pump, turn my body (mentally) while holding the credit card so that my name is facing me, and then insert the card into the machine as indicated in the diagram.

Doing so this morning, I realized that this is very similar to the Endiness issue that exists with today's microprocessors. The credit card has one side that is the most significant (the side with the magnetic stripe). Inserting a card into the reader the wrong direction results in the card not being read.

Likewise, when a computer reads a value from its I/O, it expects the bits of the value to be arranged in a certain order. If the order is reversed, then a wrong value will be read in, which can have some pretty bad consequences. Some processors are "Big Endian" (i.e., Motorola), some are "Little Endian" (i.e., Intel), and some can be switched to handle either type of Endianess (i.e., ARM, PowerPC, etc). This is where I draw the parallel to the card readers at the gasoline pumps.