Base interface for all conversion operations

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

Methods

  • Converts number into Uint8Array

    Parameters

    • num: bigint

      number to convert

    • dest: Uint8Array

      destination array

    Returns void

    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

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

    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 ]