function dec2hex(dec) { var result = "", rmd = 0; var hexst = "0123456789ABCDEF"; while (1) { if (dec >= 16) { rmd = dec % 16; dec /= 16; result = hexst.charAt(rmd) + result; } else { result = hexst.charAt(dec) + result; break; } } return result; }
function hex2dec(hex) { hex = hex.toUpperCase(); var result = 0, len = hex.length; var hexst = "0123456789ABCDEF"; for (var i=0; i<len; i++) { var ch = hex.charAt(i); result+= hexst.indexOf(ch) * Math.pow(16, len-i-1); } return result; }