IntegerToByteString

scalus.builtin.IntegerToByteString

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def integerToByteString(endiannessArg: Boolean, lengthArg: BigInt, input: BigInt): ByteString

Convert a BigInt into a ByteString.

Convert a BigInt into a ByteString.

The conversion uses fixed-width output and explicit endianness. If lengthArg is 0, the result is a minimal-length encoding.

Value parameters

endiannessArg

true for big-endian output, false for little-endian output.

input

Unsigned integer to convert. Negative integers are rejected.

lengthArg

Desired output length in bytes. If zero, the result is minimally sized. If positive, the output must fit into the exact width, otherwise an exception is thrown.

Attributes

Returns

A byte string encoded with the requested width and endianness.

Throws
scalus.uplc.eval.BuiltinException

If the requested length is negative, exceeds the maximum, or the integer cannot be represented in the requested number of bytes.

See also
Example
 // Big-endian, length 2:
 integerToByteString(true, 2, 4660) == hex"1234"
 // Little-endian, length 2:
 integerToByteString(false, 2, 4660) == hex"3412"
 // Minimal representation:
 integerToByteString(true, 0, 4660) == hex"1234"

Concrete fields