Bitcoin Forum
May 24, 2024, 06:07:33 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Little endian values in Block-header  (Read 168 times)
mechanikalk (OP)
Member
**
Offline Offline

Activity: 99
Merit: 91


View Profile WWW
November 18, 2018, 09:39:56 PM
Merited by malevolent (2), ABCbits (1), bones261 (1)
 #1

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?
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5208
Merit: 13013


View Profile
November 18, 2018, 11:11:59 PM
Merited by ABCbits (1)
 #2

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.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!