Version compl�te: jsB@nk » Calcul » Équivalent » Décimales à convertisseur binaire
URL: https://www.javascriptbank.com/decimal-to-binary-converter.html
Ce simple JavaScript convertit un nombre décimal de base en une base binaire.
Version compl�te: jsB@nk » Calcul » Équivalent » Décimales à convertisseur binaire
URL: https://www.javascriptbank.com/decimal-to-binary-converter.html
<SCRIPT language="JavaScript">function check() { dec = document.DecToBin.deci.value; if (dec == "") {alert("please insert decimal number first."); } else {scan(dec);};};function scan(ok){ var chr="1234567890"; count=0; var ex; var h;var hasil=0; for(i=0;i<ok.length;i++) { ex=ok.charAt(i); for(f=0;f<10;f++) {h=chr.charAt(f); if(h==ex){hasil=hasil+1;}; }; }; if (hasil != ok.length) { alert("put number only ->'1234567890' ."); document.DecToBin.deci.value = ""; } else{bnr();};};function bnr(){var dec=new Number(); dec=document.DecToBin.deci.value; i=dec;var hit=""; while(i >= 1) { var m=(i*10)/4; while(m > 1){m=m-5;}; if(m < 0){i=(i-1)/2;hit+="1";}else{i=i/2;hit+="0";}; };var b ="";var bin;bin=hit.length;for(a=hit.length;a>=0;a--) { b += hit.substring(a-1,a); };document.DecToBin.deci.value=b;if (b.length > 15){alert("the answer is longer than the textbox -> "+b)};}; </SCRIPT><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM name="DecToBin"><B>Type a number:</B><BR><INPUT type=text name="deci" size=15><INPUT type="Button" value="Convert to binary" onclick="check()"></FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->