Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I don't work every day with big-endian and little-endian problems and thus I find very difficult to remember which one is what.

Recently I got an interview asking the difference between the two; since I didn't remember I decided to "guess" (50% chance, after all) but I failed.

So, is there any wide known pratical trick to remember what is the difference between big endian and little endian?

share|improve this question
4  
I thin kyou are better off stating what endianess is and saying you can never remember which way round it is so you always google it –  jk. Apr 4 '12 at 11:44
    
Funny coincidence - I only stumbled on this link today, and it's surprisingly relevant commandcenter.blogspot.com/2012/04/byte-order-fallacy.html –  Nevermind Apr 4 '12 at 14:56
add comment

3 Answers

up vote 3 down vote accepted

I've always thought that it's defined the wrong way, and that's also the tip to remember it. As a non-native English speaker, I see "end" as the opposite of "start" (although obviously "end" can mean either end - the start end, or the end end). Anyway, I just remember that "it's defined the wrong way" :)

  • In big endian, the most significant (biggest) byte is in the start.
  • In little endian, the least significant (littlest) byte is in the start.

Or, referring to bit endianness:

  • 128 64 32 16 8 4 2 1 is big endian, because it ends to the little.
  • 1 2 4 8 16 32 64 128 is little endian, because it ends to the big.

Even though the usual use of the word endianness refers to how bytes are ordered within a word, its generic meaning refers to the ordering of individually addressable sub-components within the representation of a larger data item (as explained in Wikipedia).

share|improve this answer
3  
ahh, but the little-endian lilliputians started (cracked) their eggs at the little end so it is the right way round –  jk. Apr 4 '12 at 11:57
4  
-1: Endian-ness refers to bytes within a word, not bits within a byte. –  kdgregory Apr 4 '12 at 12:29
    
@kdgregory - In the end, bit numbering is impacted within a word. Have you tried bit-field structs accross different endians? I agree that the answer has it wrong, though. –  mouviciel Apr 4 '12 at 12:54
    
@Kdgregory: According to Wikipedia, endianness refers to the ordering of individually addressable sub-components within the representation of a larger data item. That's the generic case. There's also a notion of bit endianness. You're right in that the most common use of endianness refers to how bytes are ordered within a word, and my examples admittedly didn't reflect that. Replaced the first example with the common case. –  Joonas Pulakka Apr 4 '12 at 12:55
2  
@kdgregory: Since when is existence of hardware required to justify CS theoretical notions? But very well: 8051 has bit-addressable registers. Ada language allows specifying the appropriate bit order for data type representation (pdf). Transmission order of bits over a serial medium of course needs to define bit endianness. The fact that the usual use of "endianness" refers to a special case (bytes in words) doesn't invalidate its generic meaning. –  Joonas Pulakka Apr 4 '12 at 14:41
show 1 more comment

My own tip :

  • big endian = big-end first ! (the first byte (lowest address) is the MSB)
  • little endian = little-end first ! (the first byte (lowest address) is the LSB)
share|improve this answer
2  
Yes, this is the way I think of it: Big Endian "Starts at the BIG end", while Little Endian "Starts at the Little end". It's like a baseball bat, there are two ends of the bat, one is big, the other is little. It's really not that hard of a concept. –  Shane Kilkelly Apr 4 '12 at 12:29
add comment

I too have problems remembering it and there are too many confusing mnemotechnic tricks.

My only reliable help is to cast the endianness spell on google so that I get the Wikipedia article.

share|improve this answer
    
This doesn't qualify as remembering does it? –  Simon Apr 4 '12 at 13:10
    
@Simon - You are correct. I didn't answer to the question, only to the actual need behind it. –  mouviciel Apr 4 '12 at 13:26
    
Also, I cannot google during an interview :) –  Emiliano Apr 4 '12 at 16:56
    
no but you can say you would in a real situation –  jk. Apr 10 '12 at 15:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.