Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get two-digit hex from number javascript

// I created this code that converts two-digits 
// (or more) integer to hexadecimal number
var getHex=(n=0)=>{let r=0,d=n,v=[];while(d>0){r=parseInt(d%16),d=parseInt(d/16),r=r===10?'a':r===11?'b':r===12?'c':r===13?'d':r===14?'e':r===15?'f':r,v.push(r.toString())}v.length === 1 && v.push('0');return n===0?'00':v.reverse().join("")}

var myHex = getHex(29);
console.log(myHex); // output => '1d'

var anotherHex = getHex(247);
console.log(anotherHex); // output => 'f7'
 
PREVIOUS NEXT
Tagged: #hex #number #javascript
ADD COMMENT
Topic
Name
9+7 =