CCC Docs
    Preparing search index...
    • Converts a NumLike value into its hexadecimal string representation, prefixed with 0x.

      Parameters

      • val: NumLike

        The value to convert, which can be a string, number, bigint, or HexLike.

      Returns `0x${string}`

      A Hex string representing the number.

      This function returns the direct hexadecimal representation of the number, which may have an odd number of digits. For a full-byte representation (an even number of hex digits), consider using numToBytes, numLeToBytes, or numBeToBytes and then converting the resulting byte array to a hex string.

      If the normalized numeric value is negative.

      const hex = numToHex(4660); // "0x1234"
      const oddLengthHex = numToHex(10); // "0xa"