Function numberToHex

  • Convert a number to a hexadecimal string. This verifies that the number is a non-negative safe integer.

    To convert a bigint to a hexadecimal string instead, use bigIntToHex.

    Example

    numberToHex(0); // '0x0'
    numberToHex(1); // '0x1'
    numberToHex(16); // '0x10'

    Returns

    The hexadecimal string, with the "0x"-prefix.

    Throws

    If the number is not a non-negative safe integer.

    Parameters

    • value: number

      The number to convert to a hexadecimal string.

    Returns `0x${string}`