Javascript String toBin()
String.prototype.toBin = function() { var st,i,j,d;/*w w w. j av a 2 s .c o m*/ var arr = []; var len = this.length; for (i = len; i>0; i--) { d = this.charCodeAt(i-1); for (j = 0; j < 8; j++) { arr[arr.length] = d%2; d = Math.floor(d/2); } } return arr.reverse().join(""); }