Understanding Big and Little Endian Byte Order

Thanks for your reply. It let me take another run at the problem. It turns out to be a good example of the confusion that can result in “endians”. I see now that the SD card runs on the SPI protocol which is big-endian, however, the data that the big_endian SPI is transferring to the card uses the FAT file system which is little_enidian. I just have to remember that a byte is a byte, as you so correctly emphasize.

@Delron: Wow, I thought I had it rough when having to tinker around with networking :). Yeah, it helped me to realize that the endian craziness stops at the byte level, and a byte’s a byte.

Hello guys wassup?

I have a doubt…earlier this guy said that to fix the endianness issue we can use a magical number before every piece of data, n if the we read the magic number n he is 0xFEFF we have a data with the same format else if 0xFFFE we have to swap memory, but i don get the idea very well

So e.g. if i have a pixel (his order is RGBA) on a little endian machine i can use a rmask n make a AND?
Someone can help me to understand better? ^^

Kalid, hi man!

U can explain the thing about put a magic number before every data? I don get it very well =\

If i have a vector of pixels that i pick n my machine is little endian e.g., n the format of pixels is RGBA (bing endian), like this

0 X RR GG BB AA

what is the idea? How i put a magic number before this pixel n mak a test?

Thanks! ^^

Hi Shanx, good question. The “magic number” is a special header everyone agrees to write before the data.

If you’re reading data and the magic number appears backwards (0xFEFF instead of 0xFFFE), you know the data was stored in a different format and therefore you must byte-swap the data.

This is the strategy used in some Unicode documents – include a header field so people can tell when someone else wrote it differently. So, you just need to check whether the header == 0xFFFE (same byte order) or header == 0xFEFF (different byte order).

awesome is the word…plesae try to include the solution to the problem in detailed!
thanks,.

Awesome post! Thank you for writing this! :slight_smile:

@mike: Thanks!

Wow, that explained everything so thorougly. Other articles gave the basics, yet none gave you the practice.

Thanks!

Thanks for the note Michael! Yes, I find it helps to cement understanding with a real example of what’s going on.

Excellent article! Very informative with great examples, and just enough light-heartedness thrown in to make it a fun read.

I have read many other articles on endianess and somewhat understood the topic. But this was the first article I came away from feeling like I understand it well enough to explain it to someone else (the ultimate test IMHO as to whether you truly understand a topic).

Thank you for taking the time to write this. I can honestly say this knowledge will help me in my career; which in turn will help my earning potential. So you should feel very good knowing you have made such an impact in someones life via your efforts. :slight_smile:

Thanks Mark, your note made my day :). I know what you mean, it took a while for me to really get why endian problem happened, and why only for multi-byte data (single bytes and the order of bits are a common denominator that all computers agree on, otherwise we’d have the “bit ordering problem” too).

Regarding writing, I find it’s no fun for the writer or reader when done in a stuffy style. Thanks again for the comment.

thnks for this explaination I always had problem with big and little endian

many thanks for your great post.

but where should I set the commend of “setenv/export F_UFMTENDIAN=unit”? in the program, in the compile file or ?

many thanks for your great post.

but where should I set the command of “setenv/export F_UFMTENDIAN=unit”? in the program, in the compile file or ?

Great post! It was really helpful.
Thanks a lot!

great job … thanks :slight_smile:

this is good man…even i can only understand 1/4 of it…this should be enough…cheers man.

Thanks, very nice explanation …

Excellent explanation! Much Better Explained than other sources I’ve seen. Well done!