A lesson from the Computer Memory module of the bootcamp. About an 11 minute read.
A 32-bit integer is four bytes, and something has to decide which of them goes at the lowest address. Big endian puts the most significant byte first, and little endian puts the least significant byte first. Inside one machine you will never notice. The moment bytes travel to a file, a network socket or another processor, it becomes one of the most common bugs in systems programming.
Take the number 0x12345678. It needs four bytes, 12, 34, 56 and 78, and memory is a row of single bytes, so they have to be laid across four addresses in a row in some order. BIG ENDIAN puts the most significant byte, 12, at the lowest address, which matches how you write numbers on paper. LITTLE ENDIAN puts the least significant byte, 78, first. Neither is more correct. They are two conventions, each processor picks one, and everything else in this lesson follows from those two sentences. Note what does NOT change: the order of bits inside a byte, and the order of elements in an array. Endianness is only about the bytes within one value.
The rest of this lesson continues with 5 further sections. See the full curriculum.
Browse all 576 practice puzzles