Skip to content

Commit 8307e2e

Browse files
Add OP_NUMNOTEQUAL page
1 parent cace17b commit 8307e2e

2 files changed

Lines changed: 75 additions & 4 deletions

File tree

.vitepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export default {
171171
{ text: "<code>155 | OP_BOOLOR</code>", link: "/opcodes/OP_BOOLOR.md" },
172172
{ text: "<code>156 | OP_NUMEQUAL</code>", link: "/opcodes/OP_NUMEQUAL.md" },
173173
{ text: "<code>157 | OP_NUMEQUALVERIFY</code>", link: "/opcodes/OP_NUMEQUALVERIFY.md" },
174-
{ text: "<code>158 | 🚧 OP_NUMNOTEQUAL</code>", link: "/opcodes/OP_NUMNOTEQUAL.md" },
174+
{ text: "<code>158 | OP_NUMNOTEQUAL</code>", link: "/opcodes/OP_NUMNOTEQUAL.md" },
175175
{ text: "<code>159 | 🚧 OP_LESSTHAN</code>", link: "/opcodes/OP_LESSTHAN.md" },
176176
{ text: "<code>160 | 🚧 OP_GREATERTHAN</code>", link: "/opcodes/OP_GREATERTHAN.md" },
177177
{ text: "<code>161 | 🚧 OP_LESSTHANOREQUAL</code>", link: "/opcodes/OP_LESSTHANOREQUAL.md" },

opcodes/OP_NUMNOTEQUAL.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,76 @@
1-
# Work In Progress
1+
# OP_NUMNOTEQUAL
22

3-
:::warning
4-
This page has not yet been written. If you have experience with bitcoin Script and would like to contribute, please do! You can open a PR [on the repository for this website](https://github.com/thunderbiscuit/opcode-explained).
3+
:::info
4+
**Opcode number:** 158
5+
**Byte representation:** `0x9e`
6+
**Short description:** Pop the top two stack items and push 0 if both are numerically equal, else push 1.
57
:::
8+
9+
`OP_NUMNOTEQUAL` compares the top two items on the stack as integers. If they are not numerically equal, it pushes `1` (`true`) onto the stack. If they are equal, it pushes an empty array (`false`). Both items are removed from the stack after the comparison.
10+
11+
### Operation
12+
13+
1. Remove the top two items from the stack.
14+
2. Compare them as integers:
15+
- If they are **not equal**, push `1` (`true`) onto the stack.
16+
- If they are equal, push an empty array (`false`) onto the stack.
17+
3. Both original items are removed.
18+
19+
### Notes
20+
21+
- Both items must be valid integers. Bitcoin Script interprets byte arrays up to **4 bytes** as signed integers.
22+
- An empty array (`[]`) is treated as `0` when compared.
23+
- If there are fewer than two items on the stack when `OP_NUMNOTEQUAL` is executed, the script will fail.
24+
25+
## Examples
26+
27+
### Example 1: Two unequal integers
28+
29+
```shell
30+
# ASM script
31+
OP_2 OP_3 OP_NUMNOTEQUAL
32+
33+
# Raw script
34+
52539e
35+
36+
# Stack (before OP_NUMNOTEQUAL)
37+
3 # top
38+
2
39+
40+
# Stack (after OP_NUMNOTEQUAL)
41+
1 # true, as 2 != 3
42+
```
43+
44+
### Example 2: Two equal integers
45+
46+
```shell
47+
# ASM script
48+
OP_2 OP_2 OP_NUMNOTEQUAL
49+
50+
# Raw script
51+
52529e
52+
53+
# Stack (before OP_NUMNOTEQUAL)
54+
2 # top
55+
2
56+
57+
# Stack (after OP_NUMNOTEQUAL)
58+
[] # false, as 2 == 2
59+
```
60+
61+
### Example 3: Comparing zero with an empty array
62+
63+
```shell
64+
# ASM script
65+
OP_0 OP_PUSHBYTES_1 00 OP_NUMNOTEQUAL
66+
67+
# Raw script
68+
0001009e
69+
70+
# Stack (before OP_NUMNOTEQUAL)
71+
00 # top (single zero byte)
72+
[] # empty array
73+
74+
# Stack (after OP_NUMNOTEQUAL)
75+
[] # false, as 0 == [0x00]
76+
```

0 commit comments

Comments
 (0)