<p>you should use Litte-endian encoding. if the highest bit is set (range 128-255, 32768-65535 and so on) you should append the zero byte to mark these bytes as positive number.</p>

<p>So, <code>150(dec)</code> will be encoded as <code>9600</code></p>

<p><code>270(dec)</code> will be encoded as <code>0e01</code></p>

CC BY-SA 3.0
2017-10-12T12:15:41.830Z
2017-10-12T12:15:41.830Z
amaclin
<p>I want to execute a simple series of instructions to implement a bitcoin script in java using bitcoinj API. All I am looking for is performing arithmetic operations for negative integers or integers greater than 128. An example bitcoin script for the task would look like this:</p>

<p><code>150 120 OP_ADD 270 OP_CHECKNUMEQUAL</code></p>

<p>This script should return True eventually. To implement this in java, to push integer values like 150, 270 etc i have to first convert them to byte arrays. I have followed answers given in <a href="https://stackoverflow.com/questions/1936857/convert-integer-into-byte-array-java">https://stackoverflow.com/questions/1936857/convert-integer-into-byte-array-java</a> but none of them works in here probably because of differently defined arithmetic operations in bitcoinj API script. Can anyone please help me in this.</p>

CC BY-SA 3.0
2017-10-12T13:18:25.273Z
Can you post the code you have so far?
Nate Eldredge
<script><bitcoinj><java>
OP_ADD operation in bitcoin script for integers greater than 128 in java
shikhar mahajan
# OP_ADD operation in bitcoin script for integers greater than 128 in java

(Asked by: username_0 on 2017-10-12)

I want to execute a simple series of instructions to implement a bitcoin script in java using bitcoinj API. All I am looking for is performing arithmetic operations for negative integers or integers greater than 128. An example bitcoin script for the task would look like this:

`150 120 OP_ADD 270 OP_CHECKNUMEQUAL`

This script should return True eventually. To implement this in java, to push integer values like 150, 270 etc i have to first convert them to byte arrays. I have followed answers given in <https://stackoverflow.com/questions/1936857/convert-integer-into-byte-array-java> but none of them works in here probably because of differently defined arithmetic operations in bitcoinj API script. Can anyone please help me in this.

**Tags:** script, bitcoinj, java

> **Comments:**
> **username_1**: Can you post the code you have so far?  

---

## 1 answers

### Answer by username_2 on 2017-10-12. Score: 1

you should use Litte-endian encoding. if the highest bit is set (range 128-255, 32768-65535 and so on) you should append the zero byte to mark these bytes as positive number.

So, `150(dec)` will be encoded as `9600`

`270(dec)` will be encoded as `0e01`


---

