Questions tagged [endianness]

Endianness refers to how multi-byte values are stored in memory, sent between devices or stored on disk. "Big-Endian" values are stored with their most-significant byte first, and "Little-Endian" values are stored with their least-significant byte first. Other byte-orders are possible but very uncommon, and cannot be described this way.

Endianness is the organization and ordering of byte values in multi-byte words. There are two main forms of endianness: big-endian and little-endian.

Big endian (BE) means that the most significant bits are stored first (lowest address). It is similar to reading or saying the name of a decimal number in reading order.

Little endian (LE) means that the least significant bits are stored first. The bytes are stored in reverse of the big-endian format.

There are other forms of byte orderings, but they are rare. They may also be called mixed-endian.

Usage of endianness

When we talk about endian, we often refer to the endianness of an instruction architecture/CPU or the endianness of a file. The endianness of an architecture or a CPU is how the processor organizes the bits in a multi-byte word.

  • Motorola 68000 is a big-endian architecture. It stores multi-byte words in big-endian ordering.
  • Intel processors and the x86 architecture are little-endian.
  • MIPS can run in both big-endian and little-endian format, and you can select the endianness. MIPS is a Bi-endian format.

The endianness of a file indicates how the bytes of a multi-byte word is ordered in a given file (applies both to binary and text files). Sometimes, we indicate the endianness of a file by putting a byte-order mark (BOM) as the first byte of that file.

  • A big-endian UTF-16 text file with BOM would begin with the two bytes FE FF and have all the two-byte characters (each surrogate in a surrogate pair is also one character) be expressed in big endian.
  • A little-endian UTF-16 text file with BOM would begin with the two bytes FF FE and have all the two-byte characters be expressed in little endian.

Examples of endianness

A 32-bit signed int value, 12356789 is stored as four bytes in two's complement format.

  • In big endian, the value is stored as 07 5B CD 15 in hexadecimal notation.
  • In little endian, the value is stored as 15 CD 58 07 in hexadecmial notation.

A UTF-16 text file with BOM contains these characters: A 汉.

  • The BOM character has value U+FEFF. The emoji has Unicode value U+1F197 is expressed as two surrogate pairs, U+D83C U+DD97
  • In big endian, the characters are stored as FEFF 0041 0020 6C49 D83C DD97
  • In little endian, they are stored as FFFE 4100 2000 496C 3CD8 97DD

Read More

Related tags:

External links:

2109 questions
46
votes
1 answer

What's the most Pythonic way of determining endianness?

I'm trying to find the best way of working out whether the machine my code is running on is big-endian or little-endian. I have a solution that works (although I haven't tested it on a big-endian machine) but it seems a bit clunky: import…
Major Major
  • 10,286
  • 4
  • 19
  • 9
43
votes
2 answers

Can I safely assume that Windows installations will always be little-endian?

I'm writing a userspace filesystem driver on Windows and endianness conversions are something I've been dealing with, as this particular filesystem always stores values in little-endian format and the driver is expected to convert them (if…
jgottula
  • 1,346
  • 2
  • 11
  • 17
43
votes
2 answers

Is x86-64 machine language big endian?

0x0000000000400507 : 74 0c je 0x400515 0x0000000000400509 : bf 28 06 40 00 mov $0x400628,%edi .. 0x400507 : 0x28bf0c74 I think shows the machine code is big-endian. Is my conclusion right?
kern
  • 2,295
  • 4
  • 17
  • 15
43
votes
6 answers

Can endianness refer to bits order in a byte?

I'm reading "Learning Core Audio: A Hands-On Guide to Audio Programming for Mac and iOS" by Chris Adamson and at one point the author describes big-endian as: the high bits of a byte or word are numerically more significant than the lower…
Meda
  • 2,776
  • 4
  • 20
  • 31
39
votes
7 answers

C# - Binary reader in Big Endian?

I'm trying to improve my understanding of the STFS file format by using a program to read all the different bits of information. Using a website with a reference of which offsets contain what information, I wrote some code that has a binary reader…
mowwwalker
  • 16,634
  • 25
  • 104
  • 157
39
votes
2 answers

Little Endian vs Big Endian?

I'm having troubles wrapping my head on the two. I understand how to represent something in big endian. For example -12 is 1111 1111 1111 0100 But why is the little endian representation 1111 0100 1111 1111 instead of 0100 1111 1111 1111?
Clinton Jooooones
  • 887
  • 3
  • 12
  • 19
38
votes
6 answers

Building a 32-bit float out of its 4 composite bytes

I'm trying to build a 32-bit float out of its 4 composite bytes. Is there a better (or more portable) way to do this than with the following method? #include typedef unsigned char uchar; float bytesToFloat(uchar b0, uchar b1, uchar b2,…
Madgeek
  • 383
  • 1
  • 3
  • 6
38
votes
7 answers

How to write endian agnostic C/C++ code?

I did some googling and couldn't find any good article on this question. What should I watch out for when implementing an app that I want to be endian-agnostic?
d33tah
  • 10,999
  • 13
  • 68
  • 158
37
votes
2 answers

Java's Virtual Machine's Endianness

What endianness does Java use in its virtual machine? I remember reading somewhere that it depends on the physical machine it's running on, and then other places I have read that it is always, I believe, big endian. Which is correct?
JoeCool
  • 4,392
  • 11
  • 50
  • 66
37
votes
9 answers

Does my AMD-based machine use little endian or big endian?

I'm going though a computers system course and I'm trying to establish, for sure, if my AMD based computer is a little-endian machine? I believe it is because it would be Intel-compatible. Specifically, my processor is an AMD 64 Athlon x2. I…
Frank V
  • 25,141
  • 34
  • 106
  • 144
33
votes
11 answers

Is there a way to enforce specific endianness for a C or C++ struct?

I've seen a few questions and answers regarding to the endianness of structs, but they were about detecting the endianness of a system, or converting data between the two different endianness. What I would like to now, however, if there is a way to…
vsz
  • 4,811
  • 7
  • 41
  • 78
33
votes
7 answers

Testing C++ code for endian-independence

How can I test or check C++ code for endian-independence? It's already implemented, I would just like to verify that it works on both little- and big-endian platforms. I could write unit tests and run them on the target platforms, but I don't have…
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
32
votes
4 answers

Is there a way to do a C++ style compile-time assertion to determine machine's endianness?

I have some low level serialization code that is templated, and I need to know the system's endianness at compiletime obviously (because the templates specializes based on the system's endianness). Right now I have a header with some platform…
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
31
votes
9 answers

constexpr and endianness

A common question that comes up from time to time in the world of C++ programming is compile-time determination of endianness. Usually this is done with barely portable #ifdefs. But does the C++11 constexpr keyword along with template…
Charles Salvia
  • 52,325
  • 13
  • 128
  • 140
30
votes
2 answers

Details about Endian-ness and .Net?

I have a few questions about endian-ness that are related enough that I warrant putting them in as one question: 1) Is endian-ness decided by .Net or by the hardware? 2) If it's decided by the hardware, how can I figure out what endian the hardware…
Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188