Represents a hexadecimal unsigned integer value.

Hierarchy (view full)

Constructors

  • Creates a new instance of this class to represent the value built multiplying sign for the absolute value expressed by the hexadecimal digits.

    Parameters

    • sign: number

      The sign of the value.

    • digits: string

      The digits of the absolute value in hexadecimal base.

    • Optionalnormalize: ((digits: string) => string) = ...

      The function used to normalize the digits. Defaults to converting digits to lowercase.

        • (digits): string
        • Parameters

          • digits: string

          Returns string

    Returns HexUInt

Properties

digits: string

Returns the hexadecimal digits expressing this absolute value, sign and 0x prefix omitted.

An empty content results in an empty string returned.

sign: number

Represents the sign multiplier of a given number:

NEGATIVE: number = -1

Negative multiplier of the digits absolute value.

POSITIVE: number = 1

Positive multiplier of the digits absolute value.

PREFIX: "0x" = '0x'

A constant string prefix used in hexadecimal notation.

RADIX: number = 16

The radix used for representing numbers base 16 in a positional numeral notation system.

REGEX_HEX_PREFIX: RegExp = ...

Regular expression pattern to match a prefix indicating hexadecimal number.

REGEX_HEXUINT_PREFIX: RegExp = ...

Regular expression pattern to match a prefix indicating hexadecimal number.

Accessors

  • get abs(): Hex
  • Returns the absolute value of this Hex object.

    Returns Hex

    A new Hex object representing the absolute value of this Hex.

  • get bi(): bigint
  • Returns the value of bi as a BigInt type.

    Returns bigint

    The value of bi as a BigInt.

  • get bytes(): Uint8Array
  • Returns the Uint8Array representation of the aligned bytes.

    Returns Uint8Array

    The Uint8Array representation of the aligned bytes.

  • get n(): number
  • Retrieves the value of n cast from this instance interpreted as the hexadecimal expression of a bigint value.

    Returns number

    The value of n.

    If n is not within the safe number range, if the number representation of this instance results approximated.

    This class makes equal instances created from the same value as number or as bigint.

Methods

  • Compares the current Hex object with another Hex object.

    Parameters

    • that: Hex

      The Hex object to compare with.

    Returns number

    • Returns a negative number if the current Hex object is less than the given Hex object, zero if they are equal, or a positive number if the current Hex object is greater than the given Hex object.
  • Returns a new instance of the Hex class, its value fits to the specified number of digits.

    Parameters

    • digits: number

      The number of digits to fit the Hex value into.

    Returns Hex

    • A new Hex instance that represents the fitted Hex value.
    • If the Hex value cannot be fit into the specified number of digits.
  • Determines whether this Hex instance is equal to the given Hex instance.

    Parameters

    • that: Hex

      The Hex instance to compare with.

    Returns boolean

    • True if the Hex instances are equal, otherwise false.
  • Returns a string representation of the object.

    Parameters

    • compact: boolean = false

      Whether to compact the string representation.

    Returns string

    The string representation of the object.

  • Checks if the given string expression is a valid unsigned hexadecimal value.

    Parameters

    • exp: string

      The string representation of a hexadecimal value.

    Returns boolean

    • True if the expression is a valid unsigned hexadecimal value, case-insensitive, optionally prefixed with 0x; false otherwise.
  • Determines whether the given string is a valid unsigned hexadecimal number prefixed with '0x'.

    Parameters

    • exp: string

      The string to be evaluated.

    Returns boolean

    • True if the string is a valid unsigned hexadecimal number prefixed with '0x', otherwise false.
  • Create a HexUInt instance from a bigint, number, string, Uint8Array, or HexInt.

    Parameters

    • exp:
          | string
          | number
          | bigint
          | Uint8Array
          | HexInt

      The expression to be interpreted as an unsigned integer:

      • bigint is always representable in hexadecimal base notation, it throws InvalidDataType if not positive;
      • number is converted to a bigint then represented in hexadecimal base notation, it throws InvalidDataType if not a positive integer value;
      • string is parsed as the hexadecimal expression of a bigint value, optionally tagged with 0x; it throws InvalidDataType if not positive;
      • Uint8Array is interpreted as the sequence of bytes expressing a positive bigint value;
      • HexInt is interpreted as expressing a bigint value, it throws InvalidDataType if not positive.

    Returns HexUInt

    he new HexInt object representing the given exp.

    If the given expression is not a valid hexadecimal positive integer expression.

  • Generates a random Hex value of the given number of bytes length.

    Parameters

    • bytes: number

      The number of bytes to generate.

    Returns Hex

    • A randomly generated Hex value.
    • If the bytes argument is not greater than 0.

    Security auditable method, depends on