Search
 
SCRIPT & CODE EXAMPLE
 

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'
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check collision 
Javascript :: prevent form from reloading with preventDefault 
Javascript :: javascript check if key exists in object 
Javascript :: how to check if the user is in a certain guild in discord 
Javascript :: How to clear localStorage when browser/tab is closing 
Javascript :: how to store array into react-native local storage 
Javascript :: reverse key and value in object js 
Javascript :: axios pass params 
Javascript :: 413 payload too large nodejs 
Javascript :: javascript object equals 
Javascript :: check if number is negative javascript 
Javascript :: mongoose connect to URL of atals 
Javascript :: Form.Control textarea react bootstrap 
Javascript :: javascript link to another page 
Javascript :: navigate to another page in javascript 
Javascript :: react form on submit 
Javascript :: javascript get x,y point on circle 
Javascript :: Password checking regex 
Javascript :: javascript open new window and pass data 
Javascript :: redirecting to a different route if user is logged in 
Javascript :: react beforeunload 
Javascript :: react get current date yyyy-mm-dd 
Javascript :: store array in localstorage 
Javascript :: image not showing js 
Javascript :: express get form x-www-form-urlencoded 
Javascript :: javascript password validation regex test 
Javascript :: how to code number must be smaller than in javascript 
Javascript :: form submit programmatically 
Javascript :: js export as name 
Javascript :: force page to reload on back button 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =