Posts

Showing posts from February, 2023

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));

Convert string to hex code in javascript

 function convertToHex(str) {     var hex = '';     for(var i=0;i<str.length;i++) {         hex += ''+str.charCodeAt(i).toString(16);     }     return hex; }