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'
.
Ejemplos
Sintaxis
hex(n, [digits])
hex(ns, [digits])
Parámetros
value to convert.
number of digits to include.
values to convert.