<p>Little endian.</p>

<p>See, for example, the script_PushData unit test <a href="https://github.com/bitcoin/bitcoin/blob/master/src/test/script_tests.cpp#L15">in the source tree</a> that pushes one 0x5a byte onto the stack 4 different ways:</p>

<pre><code>// Check that PUSHDATA1, PUSHDATA2, and PUSHDATA4 create the same value on                                                                
// the stack as the 1-75 opcodes do.                                                                                                      
static const unsigned char direct[] = { 1, 0x5a };
static const unsigned char pushdata1[] = { OP_PUSHDATA1, 1, 0x5a };
static const unsigned char pushdata2[] = { OP_PUSHDATA2, 1, 0, 0x5a };
static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };
</code></pre>

CC BY-SA 3.0
2012-01-29T21:43:42.283Z
2012-01-29T21:43:42.283Z
gavinandresen
<p>When using <a href="https://en.bitcoin.it/wiki/Script#Constants" rel="noreferrer">OP_PUSHDATAs</a> in different Scripts, how are the next bytes denoting the amount of bytes to be pushed encoded? Are they to be treated as unsigned integer, or signed (like the data that is taken from the stack?)? Are they big endian, or little endian?</p>

<pre><code>OP_PUSHDATA1    76  0x4c    (special)   data    The next byte contains the number of bytes to be pushed onto the stack.
OP_PUSHDATA2    77  0x4d    (special)   data    The next two bytes contain the number of bytes to be pushed onto the stack.
OP_PUSHDATA4    78  0x4e    (special)   data    The next four bytes contain the number of bytes to be pushed onto the stack.
</code></pre>

<development><bitcoin-core><standard><script>
Script - OP_PUSHDATAs
ThePiachu
# Script - OP_PUSHDATAs

(Asked by: username_0 on 2011-12-20)

When using [OP\_PUSHDATAs](https://en.bitcoin.it/wiki/Script#Constants) in different Scripts, how are the next bytes denoting the amount of bytes to be pushed encoded? Are they to be treated as unsigned integer, or signed (like the data that is taken from the stack?)? Are they big endian, or little endian?

```
OP_PUSHDATA1    76  0x4c    (special)   data    The next byte contains the number of bytes to be pushed onto the stack.
OP_PUSHDATA2    77  0x4d    (special)   data    The next two bytes contain the number of bytes to be pushed onto the stack.
OP_PUSHDATA4    78  0x4e    (special)   data    The next four bytes contain the number of bytes to be pushed onto the stack.

```

**Tags:** development, bitcoin-core, standard, script


---

## 1 answers

### Answer by username_1 on 2012-01-29. Score: 8 | Accepted answer

Little endian.

See, for example, the script\_PushData unit test [in the source tree](https://github.com/bitcoin/bitcoin/blob/master/src/test/script_tests.cpp#L15) that pushes one 0x5a byte onto the stack 4 different ways:

```
// Check that PUSHDATA1, PUSHDATA2, and PUSHDATA4 create the same value on                                                                
// the stack as the 1-75 opcodes do.                                                                                                      
static const unsigned char direct[] = { 1, 0x5a };
static const unsigned char pushdata1[] = { OP_PUSHDATA1, 1, 0x5a };
static const unsigned char pushdata2[] = { OP_PUSHDATA2, 1, 0, 0x5a };
static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };

```


---

