An Example/Tutorial of using Big and Little Endian in C++
Endianness in Computer Science are talking about the byte/bit ordering used to represent data / words in a computer system. Typical cases are order in which an integer value is stored as bytes in a computer memory.
Endian is talking about Byte Order. Most computers today run on a 32 bit Word scheme. 32 bits is 4 Bytes, as 8 bits = 1 Byte. Thus A 32 bit Integer is made up of 4 Bytes.
Big Endian: In Big Endian the higher order of the byte in the number stored in memory comes at the lower address in memory (Big End Comes First). So imagine an Integer made up of Byte0,1,2,3 (4 bytes for a 32 bit integer). Byte3 would come at the lowest memory address. Big Endian ordering would look like this:
Base Address + 0 : Byte3
Base Address + 1 : Byte2
Base Address + 2 : Byte1
Base Address + 3 : Byte0
Little Endian: In Little Endian the low order byte of the number is stored in memory at the lowest address (Little End Comes first).
Base Address + 0 : Byte0
Base Address + 1 : Byte1
Base Address + 2 : Byte2
Base Address + 3 : Byte3
x86 Processors (PC’s) use Little Endian
Power PC’s (macs) use Big Endian
In the example I will show how to test for Endian type on the computer, and how to swap between Big and Little.
Big/Little Endian comes from the story of Gulliver’s Travels, from the two political parties of the Lilliputians with some who fight over cracking their soft boiled eggs open from the little or the big side.
Popularity: 27% [?]
Add A Comment
You must be logged in to post a comment.