<p>Both will work. OP_NEGATE simply XORs with 0x80, so you can also directly push the result.</p>

CC BY-SA 4.0
2018-05-06T09:30:40.390Z
And we take the absolute value of a signed integer right? In this case 10 could be written with one byte so I think that using two bytes was overkill?
Kyle Graham
CC BY-SA 4.0
2018-05-06T14:08:55.297Z
Not necessarily. Some operations, like hashing, will produce different results for positive or negative numbers. Some operations, like signatures, will fail if the R value is negative. It depends on what you're doing.
Raghav Sood
CC BY-SA 4.0
2018-05-06T23:45:48.093Z
Take into account that for numbers between -1 and 16 inclusive, short 1-byte opcodes exist. Pushing any other number (like -10) requires an explicit push operation of the bytes encoding of the number. Both "10 NEGATE" and "-10" are therefore 2-byte scripts.
Pieter Wuille
CC BY-SA 4.0
2018-05-06T09:18:30.027Z
2018-05-06T09:18:30.027Z
Raghav Sood
<p>If the user wants to push -10 onto the stack.</p>

<p>Would I do "10 OP_NEGATE" ?</p>

<p>Or could I convert it to the hex value by doing 0x80 + 10 = 0X8A ?</p>

<transactions><bitcoin-core>
How would I push a negative number with OPCODES onto the stack?
Kyle Graham
# How would I push a negative number with OPCODES onto the stack?

(Asked by: username_0 on 2018-05-05)

If the user wants to push -10 onto the stack.

Would I do "10 OP\_NEGATE" ?

Or could I convert it to the hex value by doing 0x80 + 10 = 0X8A ?

**Tags:** transactions, bitcoin-core


---

## 1 answers

### Answer by username_1 on 2018-05-06. Score: 1 | Accepted answer

Both will work. OP\_NEGATE simply XORs with 0x80, so you can also directly push the result.

> **Comments:**
> **username_0**: And we take the absolute value of a signed integer right? In this case 10 could be written with one byte so I think that using two bytes was overkill?  
> **username_1**: Not necessarily. Some operations, like hashing, will produce different results for positive or negative numbers. Some operations, like signatures, will fail if the R value is negative. It depends on what you're doing.  
> **username_2**: Take into account that for numbers between -1 and 16 inclusive, short 1-byte opcodes exist. Pushing any other number (like -10) requires an explicit push operation of the bytes encoding of the number. Both "10 NEGATE" and "-10" are therefore 2-byte scripts.  

---

