标签:blog java os 2014 javascript cti
//2->10 var b2i = function(b){ var strB = b.toString(); var sum = 0; for(var i = 0; i<strB.length ;i++){ sum += Math.pow(2,strB.length - i-1) * strB[i]; } return sum; } //10 -> 2 var r = ""; var i2b = function f(i){ if(i ==0 || i == 1){ r= i + r; return;} if(i%2 == 0){r="0"+r;} else{r="1" + r;} f( i/2 | 0 ); } //2->10 test console.log(b2i(1001)); //10->2 test i2b(18); console.log(r);
算法练习--十进制 二进制互转,布布扣,bubuko.com
标签:blog java os 2014 javascript cti
原文地址:http://blog.csdn.net/lan_liang/article/details/36877549