Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Byte Array Manipulation

Byte Manipulation

OPCODEDESCRIPTION
getbitBth bit of (byte-array or integer) A. If B is greater than or equal to the bit length of the value (8*byte length), the program fails
setbitCopy of (byte-array or integer) A, with the Bth bit set to (0 or 1) C. If B is greater than or equal to the bit length of the value (8*byte length), the program fails
getbyteBth byte of A, as an integer. If B is greater than or equal to the array length, the program fails
setbyteCopy of A with the Bth byte set to small integer (between 0..255) C. If B is greater than or equal to the array length, the program fails
concatJoin A and B
lenYields length of byte value A
substring s eA range of bytes from A starting at S up to but not including E. If E < S, or either is larger than the array length, the program fails
substring3A range of bytes from A starting at B up to but not including C. If C < B, or either is larger than the array length, the program fails
extract s lA range of bytes from A starting at S up to but not including S+L. If L is 0, then extract to the end of the string. If S or S+L is larger than the array length, the program fails
extract3A range of bytes from A starting at B up to but not including B+C. If B+C is larger than the array length, the program fails extract3 can be called using extract with no immediates.
extract_uint16A uint16 formed from a range of big-endian bytes from A starting at B up to but not including B+2. If B+2 is larger than the array length, the program fails
extract_uint32A uint32 formed from a range of big-endian bytes from A starting at B up to but not including B+4. If B+4 is larger than the array length, the program fails
extract_uint64A uint64 formed from a range of big-endian bytes from A starting at B up to but not including B+8. If B+8 is larger than the array length, the program fails
replace2 sCopy of A with the bytes starting at S replaced by the bytes of B. Fails if S+len(B) exceeds len(A) replace2 can be called using replace with 1 immediate.
replace3Copy of A with the bytes starting at B replaced by the bytes of C. Fails if B+len(C) exceeds len(A) replace3 can be called using replace with no immediates.
base64_decode edecode A which was base64-encoded using encoding E. Fail if A is not base64 encoded with encoding E
json_ref rkey B’s value, of type R, from a valid UTF-8 encoded json object A

Byte Arithmetic

The following opcodes take byte-array values that are interpreted as big-endian unsigned integers. For mathematical operators, the returned values are the shortest byte-array that can represent the returned value. For example, the zero value is the empty byte-array. For comparison operators, the returned value is a uint64.

Input lengths are limited to a maximum length of 64 bytes, representing a 512 bit unsigned integer. Output lengths are not explicitly restricted, though only b* and b+ can produce a larger output than their inputs, so there is an implicit length limit of 128 bytes on outputs.

OPCODEDESCRIPTION
b+A plus B. A and B are interpreted as big-endian unsigned integers
b-A minus B. A and B are interpreted as big-endian unsigned integers. Fail on underflow.
b/A divided by B (truncated division). A and B are interpreted as big-endian unsigned integers. Fail if B is zero.
b*A times B. A and B are interpreted as big-endian unsigned integers.
b<1 if A is less than B, else 0. A and B are interpreted as big-endian unsigned integers
b>1 if A is greater than B, else 0. A and B are interpreted as big-endian unsigned integers
b<=1 if A is less than or equal to B, else 0. A and B are interpreted as big-endian unsigned integers
b>=1 if A is greater than or equal to B, else 0. A and B are interpreted as big-endian unsigned integers
b==1 if A is equal to B, else 0. A and B are interpreted as big-endian unsigned integers
b!=0 if A is equal to B, else 1. A and B are interpreted as big-endian unsigned integers
b%A modulo B. A and B are interpreted as big-endian unsigned integers. Fail if B is zero.
bsqrtThe largest integer I such that I^2 <= A. A and I are interpreted as big-endian unsigned integers

Bitwise Operations

These opcodes operate on the bits of byte-array values. The shorter input array is interpreted as though left padded with zeros until it is the same length as the other input. The returned values are the same length as the longer input. Therefore, unlike array arithmetic, these results may contain leading zero bytes.

OPCODEDESCRIPTION
b|A bitwise-or B. A and B are zero-left extended to the greater of their lengths
b&A bitwise-and B. A and B are zero-left extended to the greater of their lengths
b^A bitwise-xor B. A and B are zero-left extended to the greater of their lengths
b~A with all bits inverted