Thursday, June 25, 2026
HomeBitcoinbitcoin core - What's the endianness of the hex strings returned by...

bitcoin core – What’s the endianness of the hex strings returned by getblockhash and getblockheader?

is that this right?

Sure, the statement about main and trailing zeroes similar to endianness appears to be like right to me.

So does getblockheader (verbose = false) return little-endian hex:

I believe it returns the header in Bitcoin’s community serialization, which has most integer values in little-endian byte-order. This conflicts with Web requirements however that is the best way Satoshi Nakamoto wished it.

and getblockhash […] return big-endian hex,

Sure. I consider Satoshi Nakamoto and different builders most well-liked to current particular person integers in big-endian as that makes most sense to conventionally educated individuals the place fifteen is written as 15 not 51 as a result of ten is greater than 5.

Why is not every thing the identical endianness?

I doubt anybody actually is aware of Satoshi Nakamoto’s intent right here. He was conscious of endianness issues in porting Bitcoin code between architectures (and I believe discouraged use of PPC because of this).

I think a few of this springs from traits of C and C++ programming and habits widespread in that neighborhood. These points may not come up in community purposes written in different programming languages and written to adapt to Web RFC requirements.

RFC1700 by Reynolds and Postel in 1994 says

When a multi-octet amount is transmitted essentially the most vital octet is transmitted first.

Bitcoin violates that rule.


The consequence is that, in Bitcoin, I discover you need to pay particular consideration to endianness and punctiliously code round it. I additionally discover that many individuals are tripped up by this.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments