|
↑
Equivalents >>>
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
Add the below code to the <body> section of your page:
<script
language="javascript"
type="text/javascript">
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;
}
function
DecimaltoAnother(A,
radix)
{
s
=
"";
while
(A
>=
radix)
{
s
+=
hex[A
%
radix];
A
=
Math.floor(A
/
radix);
}
return
transpose(s
+=
hex[A]);
}
function
transpose(s)
{
N
=
s.length;
for
(i
=
0,t
=
"";
i <
N;
i++)
t
+=
s.substring(N-i-1,
N-i);
return
t;
}
function
EvalAny(item,
r)
{
M
=
CKparseInt(item.value,
r);
for
(var
i =
0,
MyForm =
document.Converter;
i <
MyForm.length;
++i)
MyForm.elements[i].value
=
DecimaltoAnother(M,
MyForm.elements[i].name.substr(1,3));
}
</script>
<center>
<h3>Base
Conversion Function</h3><br>
<form
method="post"
name="Converter"
id="Converter">
<table
border=0
align=center>
<tr>
<td
align=right>Binary:</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>
|
→ online casino canada
|