0
How to write a js code to convert binary number into decimal?
2 Respostas
+ 3
There isn't an equivalent for binary numbers in Javascript. However you can have binary string converts into decimal using parseInt function.
console.log(parseInt('1101', 2)); // output decimal 13
+ 2
var bin = prompt('Enter a binary number (only 0 and 1, none prefix)?');
var dec = 0;
var i = bin.length;
while (i--) {
if (bin[i]=='1') dec += Math.pow(2,(bin.length-i-1));
}
alert(dec);