Converts a Number to a String with its hexadecimal value.

hex() converts a number to a string with its hexadecimal number value. Hexadecimal (hex) numbers are base-16, which means there are 16 unique digits. Hex extends the numbers 0–9 with the letters A–F. For example, the number 11 (eleven) in base-10 is written as the letter B in hex.

The first parameter, n, is the number to convert. For example, hex(20), returns the string '00000014'. If an array is passed, as in hex([1, 10, 100]), an array of hexadecimal strings is returned.

The second parameter, digits, is optional. If a number is passed, as in hex(20, 2), it sets the number of hexadecimal digits to display. For example, calling hex(20, 2) returns the string '14'.

उदाहरण

सिंटैक्स

hex(n, [digits])
hex(ns, [digits])

पैरामीटर्स

n
Number:

value to convert.

digits
Number:

number of digits to include.

ns
Number[]:

values to convert.

Returns

String: converted hexadecimal value.
Notice any errors or typos? Please let us know. Please feel free to edit src/utilities/conversion.js and open a pull request!

संबंधित संदर्भ