Categories
JavaScript Answers

How to convert binary representation of number from string to integer number in JavaScript?

Spread the love

Sometimes, we want to convert binary representation of number from string to integer number in JavaScript.

In this article, we’ll look at how to convert binary representation of number from string to integer number in JavaScript.

How to convert binary representation of number from string to integer number in JavaScript?

To convert binary representation of number from string to integer number in JavaScript, we use the parseInt function.

For instance, we write

const a = parseInt("01001011", 2);

to call parseInt with a binary string and 2 to return the decimal value of the binary string.

The 2nd argument is the radix.

Conclusion

To convert binary representation of number from string to integer number in JavaScript, we 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 *