Hexadecimal number, often known as a Hexa number, is a number with 16 digits.
It is based on the Base 16 system, also called a hexadecimal numbering system.
Example 32F or 1f,2A is a hexadecimal number.
Decimal Numbers are numbers with a base of 10, i.e. numbers ranging from 0 to 9. An example of a decimal number is 78.
the base can be 16 for Hexa, 8 for octal, and 2 for binary.
Here is a code for parsing decimal to Hexa decimal example.
let hexa1 = Number(12).toString(16); let hexa2 = Number(1918).toString(16); console.log(hexa1); // c console.log(hexa2); // 77e
toString works with numbers or integers only.
It does not work with the toString() method for a string of numbers.
let hexa1 = "12".toString(16); let hexa2 = "1918".toString(16); console.log(hexa1); //12 console.log(hexa2); //1918
The number has the parseInt method which takes the string number and base
The string is a string of numbers to convert. radix is a base such as 2, 8,16, etc.
Here is a code for convert hexadecimal to decimal example
let hexa1 = "c"; let hexa2 = "77e"; var decimal1 = parseInt(hexa1, 16); var decimal2 = parseInt(hexa2, 16); console.log(decimal1); console.log(decimal2);
In a summary, Learned the following examples.
- Convert decimal to hexadecimal number using toString() method
- Convert hexadecimal to decimal numbers using parseInt() method