EndiannessEndianness
Endianness refers to the order in which bytes are stored and read in a computer's memory.
To understand it, imagine reading directions in different languages: while English text flows from left to right, Arabic Hex flows from right to left.
Similarly, computers have two ways to store data:
- Big-endian (BE): Most significant byte first
- Little-endian (LE): Least significant byte first
1. Big-Endian1. Big-Endian
Big-endian stores the most significant byte first. This is similar to how humans read numbers and Hex in most cases: starting with the most important information.
Example: Storing the number 12345678 (hexadecimal: 0x00BC614E) in memory:
- Big-endian order:
00 BC 61 4E - Most significant byte (
00) is at the lowest memory address. - Least significant byte (
4E) is at the highest address.
Big-endian is considered more "human-readable" because the data is stored in the order we naturally read it.
2. Little-Endian2. Little-Endian
Little-endian stores the least significant byte first. While counterintuitive to humans, it's more efficient for modern processors.
Example: Storing the number 12345678 (0x00BC614E) in memory:
- Little-endian order:
4E 61 BC 00 - Least significant byte (
4E) is at the lowest memory address. - Most significant byte (
00) is at the highest address.
This "reversal" is common in Bitcoin's internal data representation.
3. Endianness in Bitcoin3. Endianness in Bitcoin
Bitcoin primarily uses little-endian for storing data like ...
Why?
why we use little endian? that's your question ?
Yes
Most modern CPUs work in little-endian, so it was likely chosen as a performance optimization. According to this site, Learn Me a Bitcoin (https://learnmeabitcoin.com/technical/general/little-endian/#why-does-bitcoin-use-little-endian), it's because Satoshi developed bitcoin on a computer with little-endian architecture.
Thanks! I just learned about this from the base58 class but didn’t the answer why little over big. Now I do!
You're very welcome!
I know what Base58 class you are talking about and that lesson is great! It's where I first learned about endianness :)