It looks like you have problems because your input is a string when you are looking for a number. Try changing your d2h () code to look like this and you should be set:
function d2h(d) { return (+d).toString(16); }
The plus sign ( + ) is an abbreviated method for forcing a variable into a number. Only the Number toString() method will take a radius, String not. In addition, your result will be lowercase, so you can force it to be capitalized using toUpperCase() :
function d2h(d) { return (+d).toString(16).toUpperCase(); }
Thus, the result will be:
d2h("28") //is "1C"
source share