Categories
JavaScript Answers

How to Convert Binary Representation of a Number from String to Integer Number in JavaScript?

Spread the love

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

For instance, we write:

const a = parseInt("01001011", 2);
console.log(a)

We call parseInt with a binary string and the radix 2, which is the radix for parsing binary numbers.

parseInt will return a decimal integer version of the binary number string.

Therefore, a is 75 according to the console log.

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 *