Converting a number from binary to decimal is a mathematical approach. We can find several mathematical algorithms to find out the decimal value of a binary number and vice versa. But implementation of those algorithms in coding just to convert a binary number to decimal number of convert a decimal number is just ridiculous.
This method can take two parameters. In the first parameter, we can pass any string. So we can pass number string and this method will convert the string to a number.
Just like this one:
If we pass “1457” this method will convert it into a number like 1457.
Now, In the second parameter, we can pass the base. That means in which number system the string is. eg, decimal, binary, hexadecimal etc.
Now you can easily predict what I am going to do to convert a decimal number to a binary number.
The default number system in which parseInt() method returns its value is decimal.
var binary = "101101"; var decimal = parseInt(binary, 2); alert(decimal);
This will give you the output in an alert box.
The full example in HTML code,
You may also read,