<p>Added two cents. In excel VBA</p>

<pre><code>Private Function Sha256String(ByVal a)
b = a
While Len(b) &gt; 0
c = c + Right(b, 2)
b = Left(b, Len(b) - 2)
Wend
Sha256String = c
End Function
</code></pre>

<hr>

<p>Run that on a and b hashes, concatenate them, double hash as hex bytes:
<a href="http://www.fileformat.info/tool" rel="nofollow">http://www.fileformat.info/tool</a>
Then run the function on the sha-256 answer.</p>

CC BY-SA 3.0
2013-12-23T22:25:38.950Z
2016-05-02T20:27:38.990Z
2016-05-02T20:27:38.990Z
criollo14
<p>As it was pointed out to me by ArtForz in this post: <a href="https://bitcointalk.org/index.php?topic=44707.msg534605#msg534605">https://bitcointalk.org/index.php?topic=44707.msg534605#msg534605</a> the hashes are stored in little endian notation, so I first need to reverse them before double-hashing them, and then reverse the output back to get the proper result.</p>

CC BY-SA 3.0
2011-09-20T00:27:28.513Z
2011-09-20T00:27:28.513Z
ThePiachu
<p>I'm trying to implement my own Markle Tree, currently I'm working on getting the hashing done correctly.</p>

<p>I've used some hashes from <a href="http://blockexplorer.com/rawblock/000000000000a85d42610b292d2baebe54ff0c854847fe3d2ca37ac7d6e46b99">http://blockexplorer.com/rawblock/000000000000a85d42610b292d2baebe54ff0c854847fe3d2ca37ac7d6e46b99</a></p>

<p>Example inputs (first two hashes from blockexplorer):</p>

<p>Ina: 3a459eab5f0cf8394a21e04d2ed3b2beeaa59795912e20b9c680e9db74dfb18c</p>

<p>Inb: be38f46f0eccba72416aed715851fd07b881ffb7928b7622847314588e06a6b7</p>

<p>Concatenated string (H1+H2): 3a459eab5f0cf8394a21e04d2ed3b2beeaa59795912e20b9c680e9db74dfb18cbe38f46f0eccba72416aed715851fd07b881ffb7928b7622847314588e06a6b7</p>

<p>Hash of concatenated string:
Ans v1: b5916d6bc34bd4157aa73c3d799a6cfcef85e0659465734362d0cebb8901e93d</p>

<p>Final hash of concatenated string:
Ans v2: 215f8397a3090a0bc8f4a2e98609a10d55fc7b939fa1ecf9803df20b1ee089a2</p>

<p>Result I got:
215f8397a3090a0bc8f4a2e98609a10d55fc7b939fa1ecf9803df20b1ee089a2</p>

<p>Expected result:
13a3595f2610c8e4d727130daade66c772fdec4bd2463d773fd0f85c20ced32d</p>

<p>Checked my calculations "manually" using <a href="http://www.fileformat.info/tool/hash.htm?hex=b5916d6bc34bd4157aa73c3d799a6cfcef85e0659465734362d0cebb8901e93d">http://www.fileformat.info/tool/hash.htm?hex=b5916d6bc34bd4157aa73c3d799a6cfcef85e0659465734362d0cebb8901e93d</a>
and got the same results.</p>

<p>Am I doing someting wrong following this example: <a href="https://en.bitcoin.it/wiki/Protocol_specification#Merkle_Trees">https://en.bitcoin.it/wiki/Protocol_specification#Merkle_Trees</a> .
I take my input hashes, concatenate them together, and double SHA256 that string. I also tried treating the input strings as a and b, that is, first double SHA256 them, and only then join them together, but the result was also wrong. Does anyone have a step-by-step example of proper hashing of the Merkle Tree?</p>

<client><development><protocol>
Merkle Tree hashing
ThePiachu
# Merkle Tree hashing

(Asked by: username_0 on 2011-09-19)

I'm trying to implement my own Markle Tree, currently I'm working on getting the hashing done correctly.

I've used some hashes from <http://blockexplorer.com/rawblock/000000000000a85d42610b292d2baebe54ff0c854847fe3d2ca37ac7d6e46b99>

Example inputs (first two hashes from blockexplorer):

Ina: 3a459eab5f0cf8394a21e04d2ed3b2beeaa59795912e20b9c680e9db74dfb18c

Inb: be38f46f0eccba72416aed715851fd07b881ffb7928b7622847314588e06a6b7

Concatenated string (H1+H2): 3a459eab5f0cf8394a21e04d2ed3b2beeaa59795912e20b9c680e9db74dfb18cbe38f46f0eccba72416aed715851fd07b881ffb7928b7622847314588e06a6b7

Hash of concatenated string:
Ans v1: b5916d6bc34bd4157aa73c3d799a6cfcef85e0659465734362d0cebb8901e93d

Final hash of concatenated string:
Ans v2: 215f8397a3090a0bc8f4a2e98609a10d55fc7b939fa1ecf9803df20b1ee089a2

Result I got:
215f8397a3090a0bc8f4a2e98609a10d55fc7b939fa1ecf9803df20b1ee089a2

Expected result:
13a3595f2610c8e4d727130daade66c772fdec4bd2463d773fd0f85c20ced32d

Checked my calculations "manually" using <http://www.fileformat.info/tool/hash.htm?hex=b5916d6bc34bd4157aa73c3d799a6cfcef85e0659465734362d0cebb8901e93d>
and got the same results.

Am I doing someting wrong following this example: <https://en.bitcoin.it/wiki/Protocol_specification#Merkle_Trees> .
I take my input hashes, concatenate them together, and double SHA256 that string. I also tried treating the input strings as a and b, that is, first double SHA256 them, and only then join them together, but the result was also wrong. Does anyone have a step-by-step example of proper hashing of the Merkle Tree?

**Tags:** client, development, protocol


---

## 2 answers

### Answer by username_0 on 2011-09-20. Score: 8 | Accepted answer

As it was pointed out to me by ArtForz in this post: <https://bitcointalk.org/index.php?topic=44707.msg534605#msg534605> the hashes are stored in little endian notation, so I first need to reverse them before double-hashing them, and then reverse the output back to get the proper result.


---

### Answer by username_1 on 2013-12-23. Score: 0

Added two cents. In excel VBA

```
Private Function Sha256String(ByVal a)
b = a
While Len(b) > 0
c = c + Right(b, 2)
b = Left(b, Len(b) - 2)
Wend
Sha256String = c
End Function

```

---

Run that on a and b hashes, concatenate them, double hash as hex bytes:
<http://www.fileformat.info/tool>
Then run the function on the sha-256 answer.


---

