|
1 | | -# Work In Progress |
| 1 | +# OP_NUMNOTEQUAL |
2 | 2 |
|
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. |
5 | 7 | ::: |
| 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