JavaScript Scripts





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Free Java Script Codes
Javascript List All
Slide Show Slide Show
Ad Display Ad Display
Image Effect Image Effect
Animated Image Effects Animated Image Effects
Form Validation Form Validation
Color Picker Tool Color Picker Tool
Formatting Forms Formatting Forms
Select All Select All
Dynamic Form Select Dynamic Form select
Dynamic Color Dynamic Color
Calendar Script Calendar
Textbox Counter Textbox Counter
Alphanumeric Alphanumeric
Date Time Script Date & Time
Stop Watch Script Stop Watch script
Delete Repeated Values Delete Repeated Values
Pagination Pagination
Random Generator Random Generator
Animated Text Animated Text
Cursor Position Cursor Position
User Info Window / User Info
Security Security / Authenticate
Bookmark Bookmark
Mouse Effects Mouse Effects
Title Bar Title Bar
Status Bar Status Bar
Country List Country List
Free Games Free Games
Calculators Calculators
 




Javascript Base Converter


About
Javascript base converter is used for number conversion,base conversion.Decimal,binary,hexadecimal,octal number conversion.


Features
a) You can convert a number to decimal,binary,octal,hexadecimal value using this javascript.
b) Just copy the code and use it.
c) This Base converter is for free use.

Preview

Base Converter

Enter a number in any one of input box

Decimal: (0..9)
Binary: (0,1)
Octal: (0..7)
Hexadecimal: (0..9,A..F,a..f)
©hscripts.com


Code
  Javascript Code
<!-- Script by hscripts.com -->
<script type="text/javascript"> function dconvert() { var dnum=parseInt(document.getElementById("deci").value); var dno=new Number(dnum); if(!isNaN(dno)) { document.getElementById("bin").value=dno.toString(2); document.getElementById("oct").value=dno.toString(8); document.getElementById("hdeci").value=dno.toString(16); } } function bconvert(bn) { var len=bn.length; var tot=0; var i,j; for(i=0,j=len-1;i<len;i++,j--) { tot=tot+parseInt(bn.charAt(i))*Math.pow(2,j); } var dec=new Number(tot); document.getElementById("deci").value=dec; document.getElementById("oct").value=dec.toString(8); document.getElementById("hdeci").value=dec.toString(16); } function oconvert(oc) { var len=oc.length; var tot=0; var i,j; for(i=0,j=len-1;i<len;i++,j--) { tot=tot+parseInt(oc.charAt(i))*Math.pow(8,j); } var dec=new Number(tot); document.getElementById("deci").value=dec; document.getElementById("bin").value=dec.toString(2); document.getElementById("hdeci").value=dec.toString(16); } function hconvert(hd) { var len=hd.length; var tot=0; var i,j; for(i=0,j=len-1;i<len;i++,j--) { ch=hd.charAt(i); if(ch=="a" || ch=="A") { tot=tot+10; } else if(ch=="b" || ch=="B") { tot=tot+11; } else if(ch=="c" || ch=="C") { tot=tot+12; } else if(ch=="d" || ch=="D") { tot=tot+13; } else if(ch=="e" || ch=="E") { tot=tot+14; } else if(ch=="f" || ch=="F") { tot=tot+15; } else { tot=tot+parseInt(hd.charAt(i))*Math.pow(16,j); } } var dec=new Number(tot); document.getElementById("deci").value=dec; document.getElementById("bin").value=dec.toString(2); document.getElementById("oct").value=dec.toString(8); } function dncheck(event,no) { var kc; if(window.event) { kc=event.keyCode; } else { kc=event.which; } var num=no.value; if (kc!=8 && kc!=0) { if (kc<48||kc>57) { return false; } } } function bncheck(event,no) { var kc; if(window.event) { kc=event.keyCode; } else { kc=event.which; } var num=no.value; if (kc!=8 && kc!=0) { if (kc!=48 && kc!=49) { return false; } } } function oncheck(event,no) { var kc; if(window.event) { kc=event.keyCode; } else { kc=event.which; } var num=no.value; if (kc!=8 && kc!=0) { if (kc<48 || kc>55) { return false; } } } function hncheck(event) { var kc; if(window.event) { kc=event.keyCode; } else { kc=event.which; } if (kc>=65 && kc<=70) { return true; } else if (kc>=97 && kc<=102) { return true; } else if (kc>=48 && kc<=57) { return true; } else if (kc==8) { return true; } else if (kc==0) { return true; } else { return false; } } </script>
<!-- Script by hscripts.com -->


   HTML Code
<!--        Script by hscripts.com          -->
<!--        copyright of HIOX INDIA         -->
<!-- Free javascripts @ http://www.hscripts.com -->
<!-- Script by hscripts.com -->

<form>
<table>
<tr><td align="right">
Decimal:</td><td><input type="text" name="deci" id="deci" onkeyup="dconvert()" onkeypress="return dncheck(event,deci)"></td></tr>
<tr><td align="right">Binary:</td><td><input type="text" name="bin" id="bin" onkeyup="bconvert(this.value)" onkeypress="return bncheck(event,bin)"></td></tr>
<tr><td align="right">Octal:</td><td><input type="text" name="oct" id="oct" onkeyup="oconvert(this.value)" onkeypress="return oncheck(event,oct)"></td></tr>
<tr><td align="right">Hexadecimal:</td><td><input type="text" name="hdeci" id="hdeci" onkeyup="hconvert(this.value)" onkeypress="return hncheck(event)"></td></tr>
</table>
</form>
&copy;<a href="http://hscripts.com">hscripts.com</a>
<!-- Script by hscripts.com -->

Release Date -07-04-2008
Get free version without ©copyright link for just 5 price

For customization of this script or any script development, contact us at support@hscripts.com


Usage
a) Copy the HTML code given above to create form
b) Copy the above Javascript code into your page and use it.
c) If the number entered in the textbox, The javascript converts the base and displays the number in binary,decimal,octal,hexadecimal format.



License
- The javascript (misspelled as java script) is given under GPL License
- i.e. Free use for those who use the codes as it is.
- Free, if your modification does not remove our copyright information and links.
- Click Here for detailed license information.
- You can purchase the script if your requirements does not meet our GPL License terms.
Other Links

web hosting