You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:** 164
5
+
**Byte representation:**`0xa4`
6
+
**Short description:** Pop the top two items; push the larger of the two onto the stack.
5
7
:::
8
+
9
+
`OP_MAX` compares the top two items on the stack as integers and pushes the larger value back onto the stack. Both original items are removed, and the larger value becomes the new top item.
10
+
11
+
### Operation
12
+
13
+
1. Pop the top item and the second item from the stack.
14
+
2. Compare the two items, and push the larger of the two values onto the stack.
15
+
16
+
### Notes
17
+
18
+
- Both items must be valid integers. Bitcoin Script interprets byte arrays up to **4 bytes** as integers.
19
+
- An empty array (`[]`) is treated as 0 when compared.
20
+
- If there are fewer than two items on the stack when `OP_MAX` is executed, the script will fail.
21
+
22
+
## Examples
23
+
24
+
### Example 1: Comparing two positive integers
25
+
26
+
```shell
27
+
# ASM script
28
+
OP_3 OP_2 OP_MAX
29
+
30
+
# Raw script
31
+
5352a4
32
+
33
+
# Stack (before OP_MAX)
34
+
2 # top
35
+
3
36
+
37
+
# Stack (after OP_MAX)
38
+
3 # larger value
39
+
```
40
+
41
+
### Example 2: Comparing a positive and a negative integer
0 commit comments