<p>You are being confused three ways.</p>

<p>First, you need to be careful that some of your numbers in decimal, others are in hexadecimal: 77 decimal -> 4d hexadecimal (so: 77<strong>d</strong> -> <strong>0x</strong>4d)</p>

<p>Second, you need to be careful that most numbers are stored in <a href="https://en.wikipedia.org/wiki/Endianness#Little-endian" rel="nofollow noreferrer">little endian notation</a>, so 0x00000001 -> 0x01000000. <a href="https://bitcoin.stackexchange.com/questions/2063/why-does-the-bitcoin-protocol-use-the-little-endian-notation">Theymos' discussion why little endian is used.</a></p>

<p>Third, you have mixed up numbers from the <a href="https://blockexplorer.com/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" rel="nofollow noreferrer">Genesis Block</a> and those from <a href="https://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d" rel="nofollow noreferrer">block 125552</a>:</p>

<p>The Genesis block nonce 2083236893d converts to 0x7c2bac1d as hexadecimal <strong>not</strong> 0x42a14695. </p>

<p>0x42a14695 is the nonce mentioned at <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Block_hashing_algorithm</a> for Block 125552, <strong>not</strong> for the Genesis block.</p>

<p>Similarly, Nbits 486604799d is for the Genesis block, 0xf2b9441a is for block 125552. Timestamp 1231469665d is for the Genesis block, 0xc7f5d74d is for block 125552.</p>

CC BY-SA 4.0
2019-03-30T14:42:45.880Z
And what the extreme programming advocates say is true, programming in pairs greatly reduces errors, fortunately I had the test battery well designed and I only had to change the asserts, thank you so much for taking me on the right track.

For the hexadecimal convention, I apologize for my mistake.

Now I would like to ask you a question, why is the nonce stored as endian bih and the versions as endian lite? there is some reference of the protocol where we talk about this to understand how to correctly convert the fields
vincenzopalazzo
CC BY-SA 4.0
2019-03-30T16:04:53.850Z
Nonce and versions are both stored as little-endian. So, the Genesis block nonce 2083236893d is 0x7c2bac1d, which is changed to its little-endian form 0x1dac2b7c before being stored.
Alistair Mann
CC BY-SA 4.0
2019-04-05T20:41:34.343Z
Thanks so much, bitcoin create the hash whit  all type little endian :) If you would not have helped me I could not solve the problem
vincenzopalazzo
CC BY-SA 4.0
2019-03-30T12:10:55.157Z
2019-03-30T12:31:23.000Z
2019-03-30T12:31:23.000Z
Alistair Mann
<p>I'm writing a blockchain parser for bitcoin core with C++ and now I want to enrich the data I read with the raw transaction and the previous and next block hashes.</p>

<p>I used this library to convert the hexadecimal to a double sha256 but now my problem is to bring the data I read into the correct format, for example, the VarInt is serialized as corresponding hexadecimal (for example 77 -> 4d).
But on some things, I don't find myself, for example in the conversion of integers of the type uint32 and int32.</p>

<p>I'll give you an example
The <strong>version</strong> number of the genesis block is <em>1</em> and the <em>serialization</em> to the correct hash is <em>01000000</em></p>

<p>or the conversion of the <strong>nonce</strong> of the genesis block which is <em>2083236893</em> but the correct form for the <strong>serialization</strong> is <em>7c2bac1d</em></p>

<p>Similarly for</p>

<p><strong>NBits</strong> = <em>486604799</em> -> <strong>serialization</strong> = <em>1d00ffff</em>
<strong>timestamp</strong> = <em>1231469665</em> -> <strong>serialization</strong> = <em>495fab29</em></p>

<p>Sorry for my terrible English but I'm learning.</p>

<p>______ Solution ______</p>

<p>Bitcoin core to use the method for serializing block, into file blk and sending data into the network, to create the hash.</p>

<p>Then, the hash block do create with all data into little endian form.</p>

<bitcoin-core><bitcoin-core-development><raw-data><c++>
How happens the serealization the data in the file blkxxxx.dat in the bitcoin
vincenzopalazzo
# How happens the serealization the data in the file blkxxxx.dat in the bitcoin

(Asked by: username_0 on 2019-03-30)

I'm writing a blockchain parser for bitcoin core with C++ and now I want to enrich the data I read with the raw transaction and the previous and next block hashes.

I used this library to convert the hexadecimal to a double sha256 but now my problem is to bring the data I read into the correct format, for example, the VarInt is serialized as corresponding hexadecimal (for example 77 -> 4d).
But on some things, I don't find myself, for example in the conversion of integers of the type uint32 and int32.

I'll give you an example
The **version** number of the genesis block is *1* and the *serialization* to the correct hash is *01000000*

or the conversion of the **nonce** of the genesis block which is *2083236893* but the correct form for the **serialization** is *7c2bac1d*

Similarly for

**NBits** = *486604799* -> **serialization** = *1d00ffff*
**timestamp** = *1231469665* -> **serialization** = *495fab29*

Sorry for my terrible English but I'm learning.

\_\_\_\_\_\_ Solution \_\_\_\_\_\_

Bitcoin core to use the method for serializing block, into file blk and sending data into the network, to create the hash.

Then, the hash block do create with all data into little endian form.

**Tags:** bitcoin-core, bitcoin-core-development, raw-data, c++


---

## 1 answers

### Answer by username_1 on 2019-03-30. Score: 1 | Accepted answer

You are being confused three ways.

First, you need to be careful that some of your numbers in decimal, others are in hexadecimal: 77 decimal -> 4d hexadecimal (so: 77**d** -> **0x**4d)

Second, you need to be careful that most numbers are stored in [little endian notation](https://en.wikipedia.org/wiki/Endianness#Little-endian), so 0x00000001 -> 0x01000000. [Theymos' discussion why little endian is used.](https://bitcoin.stackexchange.com/questions/2063/why-does-the-bitcoin-protocol-use-the-little-endian-notation)

Third, you have mixed up numbers from the [Genesis Block](https://blockexplorer.com/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f) and those from [block 125552](https://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d):

The Genesis block nonce 2083236893d converts to 0x7c2bac1d as hexadecimal **not** 0x42a14695.

0x42a14695 is the nonce mentioned at <https://en.bitcoin.it/wiki/Block_hashing_algorithm> for Block 125552, **not** for the Genesis block.

Similarly, Nbits 486604799d is for the Genesis block, 0xf2b9441a is for block 125552. Timestamp 1231469665d is for the Genesis block, 0xc7f5d74d is for block 125552.

> **Comments:**
> **username_0**: And what the extreme programming advocates say is true, programming in pairs greatly reduces errors, fortunately I had the test battery well designed and I only had to change the asserts, thank you so much for taking me on the right track.  For the hexadecimal convention, I apologize for my mistake.  Now I would like to ask you a question, why is the nonce stored as endian bih and the versions as endian lite? there is some reference of the protocol where we talk about this to understand how to correctly convert the fields  
> **username_1**: Nonce and versions are both stored as little-endian. So, the Genesis block nonce 2083236893d is 0x7c2bac1d, which is changed to its little-endian form 0x1dac2b7c before being stored.  
> **username_0**: Thanks so much, bitcoin create the hash whit  all type little endian :) If you would not have helped me I could not solve the problem  

---

