Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads | All Downloads

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Swish Templates
   SWiSH Climax
   GimpTalk
   Idea Designs
   Sposatoettore
   Try Acai Berry Diet
   Download Free Ringtones
   Swishzone

Manage your site with Flax Article Content Management System
Decimal to binary converter
Category : HTML / Javascript | Level : Beginner | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

HI all......This script will tell convert any number to binary data......
CODE
<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>

<FORM name="DecToBin"><B>Insert Number:</B>
<BR><INPUT type=text name="deci" size=15>

<INPUT type="Button" value="convert!" onclick="check()">
</FORM>


Thats it.......Dont put on too many numbers if u dont hav a ast PC...


REGARDS smile.gif


All rights reserved - swish-db.com