programming-examples/js/Math/Convert a binary number to a decimal number.js
2019-11-15 12:59:38 +01:00

6 lines
203 B
JavaScript

function bin_to_dec(bstr) {
return parseInt((bstr + '')
.replace(/[^01]/gi, ''), 2);
}
console.log(bin_to_dec('110011'));
console.log(bin_to_dec('100'));