How can I format a hexadecimal number that will always be displayed with 4 digits in javascript?
For example, I will convert the decimal to hexadecimal:
port = 23
function d2h(d) {return (+d).toString(16);}
d2h(port)
I can successfully convert "23" to the hexadecimal value of "17". However, I would like to format it as "0017" (with four digits - adding 0 to 17).
All information will be greatly appreciated.
source
share