How to use parseInt() Function In Javascript
In this approach, there is an inbuilt function parseInt which will convert the binary number into its decimal equivalent. Use the ‘parseInt’ function with base 2 to convert Binary to decimal to convert the binary string to its decimal equivalent.
Example: Demonstration of converting of binary to decimal using the inbuilt parseInt()
function binaryToDecimalParseInt(binary) {
return parseInt(binary, 2);
}
const binaryNumber = "10000";
console.log("result is : ",
binaryToDecimalParseInt(binaryNumber));
Output
result is : 16
Time Complexity: O(n).
Space Complexity: O(1).
How to convert binary to decimal in JavaScript?
A binary number is a number expressed in the binary numeral system, which uses only two symbols 0 and 1. Decimal numbers are base 10 in a JavaScript number system that uses 10 digits from 0 to 9. We are given a number as Binary input we have to convert it into decimal in JavaScript and print the result.