Decimal to hex conversion
This example containts native (toString(16)) and custom solutions for converting decimal numbers to their hexadecimal equivalents,
by djp3d
JavaScript
var n = 1128;
var n2 = 52045;
console.log(decToHex(n2));
console.log(n2.toString(8));
function decToHex(dec) {
var hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
var rem = '';
while (dec > 0) {
rem = hex[dec % 16] + rem;
dec = (dec / 16) | 0;
}
return rem;
}