<p>You only need to use OP_PUSHDATA1 if you are trying to push more than 75 bytes of data onto the stack.</p>

<p>For pushing smaller sized values onto the stack, you can use the opcodes 0x01 to 0x4b to indicate the number of bytes being pushed. Thus, to push a single byte of value 210 (0xD2) onto the stack, you would use the byte sequence <code>0x01 0xd2</code>.</p>

<p>To push a 16-bit number, such as 1000 onto the stack, you would use the sequence of bytes <code>0x02 0xe8 0x03</code>. Note that little-endian byte ordering is used. You can do similarly for a 24-bit number, or 32-bit number.</p>

<p>The minimum size should always be used when pushing a value - meaning the most significant byte of the pushed value should never be zero.</p>

<p>The value pushed will internally be zero-extended to a represent a 32-bit signed integer. All of the numeric operations in bitcoin script are limited to 32-bit integers. The result returned by a numeric operation can be treated as a signed 64-bit value, but values which overflow the 32-bit integer range may not be used in subsequent numeric operation.</p>

<hr>

<p>On OP_PUSHDATA1, this is used for pushing arbitrary binary data onto the stack which may be used as arguments for operations such as OP_SHA256. This works by having the first byte of the sequence being OP_PUSHDATA1, the second byte being the length of the pushed data, and the remaining bytes being the content. For data more than 255 bytes, OP_PUSHDATA2 is used, where the second and third bytes of the sequence represent the length, and so on. The minimum size rule applies to all of the kinds of pushes, including that you should not try to push a single byte &lt;=16 onto the stack using 2 bytes, but should instead use the OP_N single-byte opcodes.</p>

CC BY-SA 4.0
2019-04-15T13:07:59.267Z
Thanks for your reply. I want to replicate 10+120=130.
With your suggestions my script is `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL`.
But how can I replicate in hex or asm?
monkeyUser
CC BY-SA 4.0
2023-04-21T04:19:11.137Z
reference implementation will encode 210 this way `02d200` - only values up to 128 are encoded with one byte `01XX`
scagbackbone
CC BY-SA 4.0
2019-04-11T17:12:16.387Z
2019-04-11T17:12:16.387Z
Mark H
<p>To push data to the stack, if there is no opcode (i.e. there is no opcode for the number 210, but there are for the numbers 1-16: <code>OP_1 - OP_16</code>), you need to provide a push op. Since 210 can be represented in a single byte:</p>

<pre><code>OP_10 0x01 210 OP_ADD
  ^    ^    ^    ^
  |    |    |    | pop the top 2 items, add, and return result
  |    |    | Push number 210 to the stack
  |    | The next 1 byte is pushed to the stack
  | Push 10 to the stack
</code></pre>

<p>See <a href="https://en.bitcoin.it/wiki/Script#Constants" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Script#Constants</a></p>

CC BY-SA 4.0
2019-04-15T09:32:51.977Z
thanks for reply, but I don't understand a little thing.
If i want to do 10+210, my Script is `OP_10 0x02 0xD200 OP_ADD`.
Instead if I want to do 10+130, my script is `OP_10 0x02 0x8200 OP_ADD` why?
I'm using this IDE for my tests https://ide.bitauth.com/
monkeyUser
CC BY-SA 4.0
2019-04-15T09:44:34.013Z
And again, If I want to 10+120=130, in Script is `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL` and asm is `010A01789302820087`
Can I test this in IDE online?
monkeyUser
CC BY-SA 4.0
2019-04-15T11:57:46.973Z
Those scripts look correct, what do you not understand? `0xD200` is 2-byte little endian form of 210 and `0x8200` is little endian form of 130. I don't know if there is an online ide, I'm working on one, so I'll let you know when it's ready. You can also try btcdeb at https://GitHub.com/kallewoof/btcdeb
JBaczuk
CC BY-SA 4.0
2019-04-15T13:05:47.510Z
Yes it is correct, I try on ide.bitauth.com. then every number is in hex and in little endian? with btcdeb, I try with ´btcc OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL`.  Im in confusion. I'd like to know how the operation 10+120=130 is rapresent in asm and hex, and where can I try it. thanks :)
monkeyUser
CC BY-SA 4.0
2019-04-15T13:14:48.123Z
Sorry maybe i don't understand your question, you already have it in ASM, to convert to hex, just look up the code for each word: https://en.bitcoin.it/wiki/Script
JBaczuk
CC BY-SA 4.0
2019-04-15T13:18:11.533Z
My fault sorry, this is `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL` is already in asm?
monkeyUser
CC BY-SA 4.0
2019-04-15T13:40:56.673Z
Yes. There are some values there that are just values (they have no opcode) like `0x01`, `0x78`, etc.
JBaczuk
CC BY-SA 4.0
2019-04-15T13:47:52.787Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/92466/discussion-between-monkeyuser-and-jbaczuk).
monkeyUser
CC BY-SA 4.0
2019-04-15T13:49:32.570Z
but I cannot have scriptPubKey asm `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL` even if I use btcdeb.
monkeyUser
CC BY-SA 4.0
2019-04-11T17:10:36.420Z
2019-04-12T00:26:13.927Z
2019-04-12T00:26:13.927Z
JBaczuk
<p>I'm studying Script language, but I don't understand How can I rappresent the number > 16, for instance 210</p>

<p>I want to do a simple sum</p>

<pre><code>OP_10 210 OP_ADD
</code></pre>

<p>how I have to represent 210?
I'm trying with OP_PUSHDATA1 without lucky.</p>

<transactions><development><script>
Script Bitcoin represent number > 16
monkeyUser
# Script Bitcoin represent number > 16

(Asked by: username_0 on 2019-04-11)

I'm studying Script language, but I don't understand How can I rappresent the number > 16, for instance 210

I want to do a simple sum

```
OP_10 210 OP_ADD

```

how I have to represent 210?
I'm trying with OP\_PUSHDATA1 without lucky.

**Tags:** transactions, development, script


---

## 2 answers

### Answer by username_1 on 2019-04-11. Score: 5

You only need to use OP\_PUSHDATA1 if you are trying to push more than 75 bytes of data onto the stack.

For pushing smaller sized values onto the stack, you can use the opcodes 0x01 to 0x4b to indicate the number of bytes being pushed. Thus, to push a single byte of value 210 (0xD2) onto the stack, you would use the byte sequence `0x01 0xd2`.

To push a 16-bit number, such as 1000 onto the stack, you would use the sequence of bytes `0x02 0xe8 0x03`. Note that little-endian byte ordering is used. You can do similarly for a 24-bit number, or 32-bit number.

The minimum size should always be used when pushing a value - meaning the most significant byte of the pushed value should never be zero.

The value pushed will internally be zero-extended to a represent a 32-bit signed integer. All of the numeric operations in bitcoin script are limited to 32-bit integers. The result returned by a numeric operation can be treated as a signed 64-bit value, but values which overflow the 32-bit integer range may not be used in subsequent numeric operation.

---

On OP\_PUSHDATA1, this is used for pushing arbitrary binary data onto the stack which may be used as arguments for operations such as OP\_SHA256. This works by having the first byte of the sequence being OP\_PUSHDATA1, the second byte being the length of the pushed data, and the remaining bytes being the content. For data more than 255 bytes, OP\_PUSHDATA2 is used, where the second and third bytes of the sequence represent the length, and so on. The minimum size rule applies to all of the kinds of pushes, including that you should not try to push a single byte <=16 onto the stack using 2 bytes, but should instead use the OP\_N single-byte opcodes.

> **Comments:**
> **username_0**: Thanks for your reply. I want to replicate 10+120=130. With your suggestions my script is `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL`. But how can I replicate in hex or asm?  
> **username_2**: reference implementation will encode 210 this way `02d200` - only values up to 128 are encoded with one byte `01XX`  

---

### Answer by username_3 on 2019-04-11. Score: 1

To push data to the stack, if there is no opcode (i.e. there is no opcode for the number 210, but there are for the numbers 1-16: `OP_1 - OP_16`), you need to provide a push op. Since 210 can be represented in a single byte:

```
OP_10 0x01 210 OP_ADD
  ^    ^    ^    ^
  |    |    |    | pop the top 2 items, add, and return result
  |    |    | Push number 210 to the stack
  |    | The next 1 byte is pushed to the stack
  | Push 10 to the stack

```

See <https://en.bitcoin.it/wiki/Script#Constants>

> **Comments:**
> **username_0**: thanks for reply, but I don't understand a little thing. If i want to do 10+210, my Script is `OP_10 0x02 0xD200 OP_ADD`. Instead if I want to do 10+130, my script is `OP_10 0x02 0x8200 OP_ADD` why? I'm using this IDE for my tests https://ide.bitauth.com/  
> **username_0**: And again, If I want to 10+120=130, in Script is `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL` and asm is `010A01789302820087` Can I test this in IDE online?  
> **username_3**: Those scripts look correct, what do you not understand? `0xD200` is 2-byte little endian form of 210 and `0x8200` is little endian form of 130. I don't know if there is an online ide, I'm working on one, so I'll let you know when it's ready. You can also try btcdeb at https://GitHub.com/kallewoof/btcdeb  
> **username_0**: Yes it is correct, I try on ide.bitauth.com. then every number is in hex and in little endian? with btcdeb, I try with ´btcc OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL`.  Im in confusion. I'd like to know how the operation 10+120=130 is rapresent in asm and hex, and where can I try it. thanks :)  
> **username_3**: Sorry maybe i don't understand your question, you already have it in ASM, to convert to hex, just look up the code for each word: https://en.bitcoin.it/wiki/Script  
> **username_0**: My fault sorry, this is `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL` is already in asm?  
> **username_3**: Yes. There are some values there that are just values (they have no opcode) like `0x01`, `0x78`, etc.  
> **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/92466/discussion-between-username_0-and-username_3).  
> **username_0**: but I cannot have scriptPubKey asm `OP_10 0x01 0x78 OP_ADD 0x02 0x8200 OP_EQUAL` even if I use btcdeb.  

---

