Author -  Sai gowtham

Converting (binary,hex,octal) to decimal numbers in JavaScript

In this tutorial, we are going to learn about how to convert binary, hexadecimal and octal to decimal numbers in JavaScript.

parseInt

In JavaScript, we have the parseInt() method by using that we can make conversions.

The parseInt( ) method takes the two arguments, the first argument is string and the second argument is base by using that it returns the decimal number of a specified base.

Let’s see the conversions with the help of examples.

Converting binary to decimal

To convert a binary to decimal we need to pass base 2 as a second argument to the parseInt method.


const binaryNumber = "1100";

console.log(parseInt(binaryNumber,2)); // base 2

//output--> 12

Converting hexadecimal to decimal

To convert a hexadecimal to decimal we need to pass base 16 as a second argument to the parseInt method.


const hex = "c";

console.log(parseInt(hex,16));  //hex base-16

//output --> 12

Converting octal to decimal

To convert a octal to decimal we need to pass base 8 as a second argument to the parseInt method.

const octal = "14";

console.log(parseInt(octal,8));  //octal base-8

//output --> 12

You can also learn, how to convert decimal to (binary, hexadecimal, octal) numbers in JavaScript.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY