Skip to main content

Command Palette

Search for a command to run...

JS: Decimal and Hexadecimal

Updated
1 min read
JS: Decimal and Hexadecimal
A

A Tech Lead by profession, a Data Enthusiast and a forever learner. Experienced in DevOps, Cloud, FullStack Development, Data Science, Machine Learning and AI.

This is pretty interesting how you can convert not just standard decimal or hexadecimal numbers but any number with a base between 2 and 32. Here’s how:

var myDecimalNum = 10; 
myDecimalNum.toString(16); 

// result : a
var myHexNum = "a"; 
parseInt(myHexNum,16); 

// result : 10

And not just base 16 (hex), you can do it for any base. Try different bases and have fun.

More from this blog

A

Anupam Majhi

28 posts

Tech Lead | DevOps, Cloud, FullStack, Data Science, Machine Learning, AI