base converter




JavaScript Source Code 3000: Equivalents: Base Converter








































Base Converter







Converts input between binary, ternary, quintal, octal, decimal, and hexadecimal bases. Try entering a string of zeroes and ones in the binary field - when you click off, the script displays that number of the other bases.





Base Conversion Function



Binary:



Ternary:


Quintal:



Octal:



Decimal:



Hexadecimal:









JavaScript Source Code 3000: Equivalents: Base Converter
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!





    





<!-- TWO STEPS TO INSTALL BASE CONVERTER:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Mike Maloney -->
<!-- Web Site: http://nfg.natfuel.com -->

<! >
<! >

<!-- Begin
var hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
function CKparseInt(n, r) {
for (var i = 0; i < n.length; ++i)
if (n.charAt(i) >= r) {
alert("Invalid digit");
return 0;
}
if (isNaN(M = parseInt(n, r)))
alert ("Invalid number");
return M;
}
// decimal to any other base 2 to 16
function DecimaltoAnother(A, radix) {
s = "";
while (A >= radix) {
s += hex[A % radix]; // remainder
A = Math.floor(A / radix); // quotient, rounded down
}
return transpose(s += hex[A]);
}
// string reversal
function transpose(s) {
N = s.length;
for (i = 0,t = ""; i < N; i++)
t += s.substring(N-i-1, N-i); // s.substring(from, to)
return t;
}
// convert item.value using radix
function EvalAny(item, r) {
M = CKparseInt(item.value, r); // check this one
for (var i = 0, MyForm = document.forms[0]; i < MyForm.length; ++i) // re-evaluate all
MyForm.elements[i].value = DecimaltoAnother(M, MyForm.elements[i].name.substr(1,3));
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<h3>Base Conversion Function</h3><br>
<form method="post">
<table border=0 align=center>
<tr>
<td align=right><p>Binary:</p></td>
<td><input name="b002" value="0" onChange="EvalAny(this, 2)" size=27></input></td>
</tr>
<tr>
<td align=right>Ternary:</td>
<td><input name="t003" value="0" onChange="EvalAny(this, 3)" size=21></input></td>
</tr>
<tr><td align=right>Quintal:</td>
<td><input name="q005" value="0" onChange="EvalAny(this, 5)" size=16></input></td>
</tr>
<tr>
<td align=right>Octal:</td>
<td><input name="o008" value="0" onChange="EvalAny(this, 8)" size=12></input></td>
</tr>
<tr>
<td align=right>Decimal:</td>
<td><input name="d010" value="0" onChange="EvalAny(this, 10)" size=11></input></td>
</tr>
<tr>
<td align=right>Hexadecimal:</td>
<td><input name="h016" value="0" onChange="EvalAny(this, 16)" size=8></input></td>
</tr>
</table>
</form>
</center>



<!-- Script Size: 2.50 KB -->











Wyszukiwarka

Podobne podstrony:
function base convert
function base convert
base (4)
grice opracowaniE Cooperative Principle, Maxims of Conversation
PS4 ZB4 501 UM3 UM4 Interface Converter h1371g
Laszlo, Ervin The Convergence of Science and Spirituality (2005)
CHRYSLER LEBARON CONVERT COUPE 1990
dvd do divx divx converter
Mazatrol Fusion Conversational Programming Class for 640MT & MT Pro For Integrex Outline
Super kalkulator konwerter CONVERT
Active DWG DXF Converter
Conversion
Lab31 R1 Base Cfg
techniques de base
Larry Niven Passing Perry Crater Base, Time Uncertain

więcej podobnych podstron