Base interface for all conversion operations

interface Convert {
    toArray(num, dest): void;
    toBigInt(arr): bigint;
    toNewArray(num, bytes): Uint8Array;
}

Methods

  • Converts number into Uint8Array

    Parameters

    • num: bigint

      number to convert

    • dest: Uint8Array

      destination array

    Returns void

    Throws

    RangeError if bigint does not fit into dest

  • Converts Uint8Array into number

    Parameters

    • arr: Uint8Array

      Uint8Array to convert

    Returns bigint

    number

  • Converts number into new Uint8Array

    Parameters

    • num: bigint

      number to convert

    • bytes: number

      number of bytes the result should have

    Returns Uint8Array

    Uint8Array

    Throws

    RangeError if bytes is less than 1 or number does not fit into bytes

    Example

    converter.unsigned.be.toNewArray(1n, 2) // Uint8Array [ 0x00, 0x01 ]
    converter.unsigned.be.toNewArray(-1n, 2) // RangeError: requested bigint is negative
    converter.signed.be.toNewArray(-1n, 2) // Uint8Array [ 0xff, 0xff ]

Generated using TypeDoc