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.
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
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
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.
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