
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert decimal to hexadecimal in JavaScript?
The number class has a toString method that accepts base as argument. We can pass base 16(hex numbers) to get the desired number converted to hexadecimal string.
Example
console.log(Number(255).toString(16)) console.log(Number(17).toString(16))
Output
ff 11
We can convert these numbers back to decimal using the parseInt function. The parseInt function available in JavaScript has the following signature −
parseInt(string, radix);
Where, the paramters are the following −
string −The value to parse. If this argument is not a string, then it is converted to one using the ToString method. Leading whitespace in this argument is ignored.
radix −An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string.
So we can pass the string and the radix and convert any numbner with base from 2 to 36 to integer using this method.
Example
console.log(parseInt("ff", 16)) console.log(parseInt("11", 16))
Output
255 17
- Related Questions & Answers
- How to Convert Decimal to Hexadecimal?
- How to Convert Hexadecimal to Decimal?
- How to convert Decimal to Hexadecimal in Java
- Java Program to convert from decimal to hexadecimal
- Convert decimal integer to hexadecimal number in Java
- Java program to convert decimal number to hexadecimal number
- Java Program to convert hexadecimal number to decimal number
- Java Program to convert decimal integer to hexadecimal number
- How to Convert Decimal to Binary, Octal, and Hexadecimal using Python?
- How to convert Decimal to Binary in JavaScript?
- How to convert Binary to Decimal in JavaScript?
- How to Convert Binary to Hexadecimal?
- C++ program for hexadecimal to decimal
- Program for decimal to hexadecimal conversion in C++
- How to Convert Binary to Decimal?
Advertisements