nodejs binary string to decimal number
// Binary string
const binaryString = '1101101';
// Convert binary string to decimal number
const decimalNumber = parseInt(binaryString, 2);
// Output
console.log(decimalNumber);
- Declare a variable
binaryString
and assign a binary string to it. - Use the
parseInt
function to convert the binary string (binaryString
) to a decimal number. The second parameter2
specifies that the input is in base-2 (binary). - Store the result in the variable
decimalNumber
. - Output the decimal number to the console.