convert decimal to hexadecimal in javascript
function convertToHex(n) {
let hex = n.toString(16).toUpperCase();
if (hex.length < 2) {
hex = `0${hex}`;
}
return hex;
}
console.log(convertToHex(12));
function convertToHex(n) {
let hex = n.toString(16).toUpperCase();
if (hex.length < 2) {
hex = `0${hex}`;
}
return hex;
}
console.log(convertToHex(12));
Comments
Post a Comment