Categories
JavaScript Answers

How to convert binary string to decimal with JavaScript?

Spread the love

Sometimes, we want to convert binary string to decimal with JavaScript.

In this article, we’ll look at how to convert binary string to decimal with JavaScript.

How to convert binary string to decimal with JavaScript?

To convert binary string to decimal with JavaScript, we can use the parseInt function.

For instance, we write

const binary = "1101000";
const digit = parseInt(binary, 2);
console.log(digit);

to call parseInt with the binary binary string and 2 to return the binary string parsed into a decimal number.

Conclusion

To convert binary string to decimal with JavaScript, we can use the parseInt function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *