0
Can someone help me in explaining this code. Thanks in anticipation.
var bin="1011"; function bin_to_dec(bin){ var dec=0; var pow=1; var len=bin.length; for(var i=len-1; i==0; i--) { dec+=bin[i]*pow; pow*=2; } return dec; } console.log(bin_to_dec(bin)); //11
3 Respuestas
+ 5
The function bin_to_dec converts an binary number to decimal Through starting at the very right number and multiplying it with 1. Then it takes the next number from the right and mulytplies it with 2. This ks done for all digits and added to dec, so dec is the decimal value of bin. This is returned...
+ 3
You are welcome
+ 1
Thank you!!! That's quite helpful.