<p>The value of <code>previousblockhash</code> in <code>getmemorypool</code> output is the block hash in big-endian order.</p>

<p>The value of <code>data</code> in <code>getwork</code> output is formatted as I described in <a href="https://bitcoin.stackexchange.com/a/2907/659">this answer</a> to <a href="https://bitcoin.stackexchange.com/q/2906/659">your question</a> about how <code>hash1</code> is calculated.</p>

<p>This byte order reversal on 4 byte words is done by a function called <code>FormatHashBuffers</code> in <code>main.cpp</code>.  It's only done for the <code>data</code> and <code>hash1</code> fields of the <code>getwork</code> output.  There's no comment explaining why it's done.</p>

CC BY-SA 3.0
2012-02-15T23:43:24.050Z
2012-02-15T23:43:24.050Z
2017-04-13T12:47:33.283Z
Chris Moore
<p>When I called:</p>

<pre><code>print bitcoin.getmemorypool()
print bitcoin.getwork()
</code></pre>

<p>using Python JSON for a testnet BitcoinQT server, I got the following responces:</p>

<pre><code>{'previousblockhash': '00000000032e361b246e96c4e594523b6ff42bc0527e560f203fb20a08a86185', 'transactions': ..., 'version': 1, 'coinbasevalue': 5000400000, 'time': 1329342730, 'bits': '1c2336a4'}
{... 'data': '0000000108a86185203fb20a527e560f6ff42bc0e594523b246e96c4032e361b000000004c50804820b143e1583c8c49dd43a6ddb8bc777c57c2da4a92b39ee0e709bf504f3c290b1c2336a400000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000', ...}
</code></pre>

<p>Comparing the previous block hash from GetMemoryPool and one extracted from the block header from Getwork:</p>

<pre><code>00000000 032e361b 246e96c4 e594523b 6ff42bc0 527e560f 203fb20a 08a86185
08a86185 203fb20a 527e560f 6ff42bc0 e594523b 246e96c4 032e361b 00000000
</code></pre>

<p>From what I can see, the data is reversed in chunks of 4 bytes. Why is such a procedure done, and what other fields from those two RPC calls undergo such an operation? </p>

CC BY-SA 3.0
2012-02-15T22:09:00.730Z
Like, seriously, it's bad enough that Bitcoin uses two different endiannesses on bytes, now we also have a little endianness of a big endianness words (I guess that's what one would call a set of 4 bytes?)?
ThePiachu
<protocol><json-rpc><getwork><getmemorypool><endianness>
Getwork and GetMemoryPool - why is previous block hash different?
ThePiachu
# Getwork and GetMemoryPool - why is previous block hash different?

(Asked by: username_0 on 2012-02-15)

When I called:
print bitcoin.getmemorypool()
print bitcoin.getwork()

using Python JSON for a testnet BitcoinQT server, I got the following responces:
{'previousblockhash': '00000000032e361b246e96c4e594523b6ff42bc0527e560f203fb20a08a86185', 'transactions': ..., 'version': 1, 'coinbasevalue': 5000400000, 'time': 1329342730, 'bits': '1c2336a4'}
{... 'data': '0000000108a86185203fb20a527e560f6ff42bc0e594523b246e96c4032e361b000000004c50804820b143e1583c8c49dd43a6ddb8bc777c57c2da4a92b39ee0e709bf504f3c290b1c2336a400000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000', ...}

Comparing the previous block hash from GetMemoryPool and one extracted from the block header from Getwork:
00000000 032e361b 246e96c4 e594523b 6ff42bc0 527e560f 203fb20a 08a86185
08a86185 203fb20a 527e560f 6ff42bc0 e594523b 246e96c4 032e361b 00000000

From what I can see, the data is reversed in chunks of 4 bytes. Why is such a procedure done, and what other fields from those two RPC calls undergo such an operation?

**Tags:** protocol, json-rpc, getwork, getmemorypool, endianness

> **Comments:**
> **username_0**: Like, seriously, it's bad enough that Bitcoin uses two different endiannesses on bytes, now we also have a little endianness of a big endianness words (I guess that's what one would call a set of 4 bytes?)?  

---

## 1 answers

### Answer by username_1 on 2012-02-15. Score: 1 | Accepted answer

The value of `previousblockhash` in `getmemorypool` output is the block hash in big-endian order.

The value of `data` in `getwork` output is formatted as I described in [this answer](https://bitcoin.stackexchange.com/a/2907/659) to [your question](https://bitcoin.stackexchange.com/q/2906/659) about how `hash1` is calculated.

This byte order reversal on 4 byte words is done by a function called `FormatHashBuffers` in `main.cpp`. It's only done for the `data` and `hash1` fields of the `getwork` output. There's no comment explaining why it's done.


---

