d.toString(16)

Beautifully simple way to get a hex value from a number. Note that d is a number. If you want a string as a hex XML valid code, use:

'&#x' + parseInt(number).toString(16).toUpperCase() + ';'

MY EBOOK£5 for Working the Command Line

Gain command-line shortcuts and processing techniques, install new tools and diagnose problems, and fully customize your terminal for a better, more powerful workflow.