onlinecode

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

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

In this post we will give you information about Converting (binary,hex,octal) to decimal numbers in JavaScript. Hear we will give you detail about Converting (binary,hex,octal) to decimal numbers in JavaScriptAnd how to use it also give you demo for it if it is necessary.

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.

Hope this code and post will helped you for implement Converting (binary,hex,octal) to decimal numbers in JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version