BSV.ScriptNum (BSV v2.1.0) View Source

A ScriptNum is an integer encoded as little-endian variable-length integers with the most significant bit determining the sign of the integer.

Used in Bitcoin Script for arithmetic operations.

Link to this section Summary

Types

t()

ScriptNum binary

Functions

Decodes the given ScriptNum binary into an integer.

Encodes the given integer into a ScriptNum binary.

Link to this section Types

Specs

t() :: binary()

ScriptNum binary

Link to this section Functions

Specs

decode(binary()) :: integer()

Decodes the given ScriptNum binary into an integer.

Examples

iex> BSV.ScriptNum.decode(<<100>>)
100

iex> BSV.ScriptNum.decode(<<160, 134, 1>>)
100_000

iex> BSV.ScriptNum.decode(<<0, 232, 118, 72, 23>>)
100_000_000_000

Specs

encode(number()) :: binary()

Encodes the given integer into a ScriptNum binary.

Examples

iex> BSV.ScriptNum.encode(100)
<<100>>

iex> BSV.ScriptNum.encode(100_000)
<<160, 134, 1>>

iex> BSV.ScriptNum.encode(100_000_000_000)
<<0, 232, 118, 72, 23>>