Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: mechanikalk on November 18, 2018, 09:39:56 PM



Title: Little endian values in Block-header
Post by: mechanikalk on November 18, 2018, 09:39:56 PM
Does anyone have any idea why Satoshi made all values in the block-header stored as little endian in byte code except for the Merkle root?  It is a frustrating thing when working with code and I can't figure out why it would have been done this way?  Any guesses or thoughts or reasonings for this?


Title: Re: Little endian values in Block-header
Post by: theymos on November 18, 2018, 11:11:59 PM
The Merkle root is also little-endian...

As to why, it's because the fields are read/written directly between memory and the socket, and that's how the data is ordered in memory. Integers are little-endian in memory because that's how the supported architectures do things. It's a little weird that hashes are stored little-endian, but Satoshi put most hashes in a uint256 type which behaved how you'd expect a 256-bit integer to behave on eg. x86, including little-endianness.