Wow... 1 week of not posting and look what you get. *Whistles* Blogger has really spiced it up.
But anyway, on to the point at hand. I was reading along in STL's website when what do I find? "Little Endian is evil"
I sat there stunned, "Did he just say what I thought he said?" And sure enough, he had. And I'm like, WOAH! A CS guy who doesn't see the silent beauty of little endian? Blastphemy!
Maybe it's just because I'm an Electrical Engineering student instead of a CS student (Although the current plan is to minor in CS) but little-endian numbers are to me what chocolate is to most. See, for those of you who are just plain ol' technically inclined (This topic is WAY beyond 'computer literate') I'll give a quick discussion of Big and Little endian numbers. See, computers keep their data in discrete digits, namely ones and zeros. Now these digits are combined together to form larger chunks of data. Often they're arranged into groups of bytes, words, D-words, and Quad-words (On 32 bit systems, these are 8,32,64, and 128 bits in size respectively.) Now, because numbers are usually made of values larger than one measly byte can hold, we use the larger words to hold them. But because memory is arranged into bytes for addressing purposes, we have to decide how they should be stored. Big endian uses the same principle as you would with notebook paper. If the top left corner of the page is the first spot, it would begin by writing the most significant (the 5 in the number 51223) digit first (or the most significant byte (MSB) in this case.) The last one it would write would be the least significant. Now this would seem obvious to anyone who's written on paper before, but little-endian takes a different approach. Instead of writing the MSB first, it writes the least significant byte (LSB) first. So this is like representing fifty-one thousand, two-hundred and twenty-three by writing 32215 down on the paper. Now this is counter intuitive to most people. Why would you write the last digit first?
This takes us into the beauty of little-endian numbers. Now, stop a second and add the numbers 123 and 789 together, taking notice of how you did it. Notice that you started the addition from the RIGHT and worked left? Now pretend that you could only read one digit at a time and couldn't rewind either the input number or the output numbers. Can you think of any way to do the addition under those constraints? You can't do it without first having yet ANOTHER sheet of paper to hold the values on for a moment. And it would take you a second to copy the numbers down. Now, consider how you would do it if the least significant digit (The one on the right) came first. For me, I'd do our example (123+789) by going: "OK, I have 3 and 9, add, get 2 and a carry. Now I have 2 and 8 and a carry, add, get 1 and a carry. Now I have 1 and 7 and a carry, add get 9. Now the answer I gave is 219, which is correct (in little-endian notation, the answer in common form is 912.) Notice, I was able to do the addition serially (one digit at a time with no look ahead) with only a one bit buffer (notice, I DO have to keep track of the carry.) Because of this, circuits of VERY low complexity can be designed and built to do addition as the numbers are read in. This is very fast and very efficient. Fewer gates mean fewer transistors, means less heat, means higher clock rates, etc. This holds true even if your bus is larger than 8 bits.
But this leads us into one of the pitfalls of big-endian numbers. Since bytes themselves are stored such that the lowest order bit is also the least significant bit, that means that a big endian system has it's bits ordered such that a 2 byte number is written in memory as (using bytenumber(bitnumber) notation) 1(0),1(1),1(2),1(3),1(4),1(5),1(6),1(7),0(0),0(1),0(2),0(3),0(4),0(5),0(6),0(7). Notice how the biggest byte is first but the biggest bit is last? Little endian puts the biggest byte last as WELL as the biggest bit. This means that the bits are ALSO sorted linearly by significance. This is very useful when doing significance (> and <) checks, since with little endian you can start at the very beginning of the two numbers and check them as you go (1 loop), rather than having to skip around to find the next most significant bit (1 loop and another nested loop. Oh, and usually > and < are done with subtraction instead, but there are other kinds of algorithms that bennifit by having sorted bits.)
But, unfortunately, little-endian is just backwards from what we're used to in significance, so programmers, like STL, just don't nessicarily see the essential beauty on the lower level.
Mood: Actually informed by a class... Scary huh?