programming-examples/js/Math/Convert a binary number to a decimal number.js

6 lines
203 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function bin_to_dec(bstr) {
return parseInt((bstr + '')
.replace(/[^01]/gi, ''), 2);
}
console.log(bin_to_dec('110011'));
console.log(bin_to_dec('100'));