Little Endian vs. Big Endian

xiaoxiao2021-03-06  80

[Note: This was originally written for "FYI", the internal newsletter for the worldwide software engineering departments of Dendrite International] Usually, the first thing a programmer who is used to larger machines says when encountering a Intel-based system is, "Why do they store their numbers backwards? "The answer is, of course, that they do not. The technical phrasing of the question is" Why does Intel uses 'Little Endian' addressing as supposed to 'Big Endian'? ", which is somewhat less judgmental on which is the "correct" way of doing it. For good reason-there are strong arguments that Little Endian is the "logical" way to do it. Computer memory is a rather nebulous thing. How can you say that one byte is to the "left" or the "right" of another byte in memory. You can point to a hex dump, but that's merely one particular graphic representation of the computer memory. And it's not the only one, nor is it necessarily the "Best" or "Correct" One. Consider for a moment how We Numbe Rate Sensible Program Would Number The Rightmost Bit "0", The Bit To The Left of That "1", The next "2" and so on, with each label corresponding to the power of two replencents (NOTE: IBM 370 Assembler, Bits Are Numbered 1 To 32, Left TO Right, Which is why i started that lastsence "Most Sensible Program"

) SO, Let Us PONDER A Number Made Up of Just One Bit-That Bit Up of Just One To Two Bits, The Original Bit Stays Where It Is At Address 0, And The New Bit Is Added to the left, at address 1. You will notice that we can make this number any size, simply by adding digits to the left. Now, we extend this idea to bytes. A number made up of just one byte would have that byte placed at address 0. 0 1 2 3 4 5 6 7 8 9 A B C D E F 0000 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 But now, how do we expand this number to two bytes? We have two options here We could allow it to grow towards the right -.. the Intel (little endian form) 0 1 2 3 4 5 6 7 8 9 A B C D E F 0000 21 43 00 00 00 00 00 00 00 00 00 00 00 00 This Puts The Numbers "Backwards", But Allows US To Extend The Size of Number To The Limits of Memory WITHOUT ACTUALLY Changing It's Values ​​(IE "21 43", 21 43 00 ", And" 21 43 00 00 "Are All the Same N UMber). Alternately, We Could Slide the first byte to the right, changing it's address, and kil rt ^ 0 1 2 3 4 5 6 7 8 9 A b C D e f 0000 43 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00- - forces a definite size Into the Number (IE "43 21", "43 21 00", And "43 21 00 00 "

Refer to Three Different Values). Neither Method Works The Same As It Did with Bits. The Problem IS, BASICLY, THAT We ​​don't address bytes the Same Way As We address Bits (Left-to-Right vs. Right-to- . left) However, there's nothing really forcing us to number bytes from left to right If we wanted to, we could number them right to left If we were to do so, the above exercise takes on a whole new look:.. F E D C B A 9 ​​8 7 6 5 4 3 2 1 0 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 grows to become either (Little Endian): F E D C B A 9 ​​8 7 6 5 4 3 2 1 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 1 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 1 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 43 Suddenly, the little endian version not only looks correct, but also reactions correctly, as it can grow to the left without affecting it's existing bytes. And, just as suddenly, the big endian method Turns ONTO A BIZARR E Rogue whose byte ORDERING DOESN'T FOLLOW Any of The "Rules". A FEW MONTHS AGO, A Problem Arose As We Converted The host from a 32-bit to 64-bit machine. The Original Machines-RS / 6000S WERE BIG ENDIAN machine, while the new systems, DEC Alphas, used little endian. The problem was partly caused by the difference in word size, but the fact that the old machines had their numbers "backwards" was involved. The example given in the Dec. 93 Fyi Was of the Number 3781 Which The IBMS WANTED REPRESENTED AS "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"

转载请注明原文地址:https://www.9cbs.com/read-93533.html

New Post(0)