C
Cogito
I'm playing around with code to convert numbers from decimal to
hexadecimal and vice versa. I was able to get the 'decimal to hex'
part going. But, I have no idea how to do the hex to decimal part.
Can you show me in the following sample what needs to be added?
<html>
<head>
<script language="JavaScript">
<!--
function HexCalc(op) {
var a;
var n1 = eval(document.CalcForm.num1.value);
if (op == "tohex") a = n1.toString(16).toUpperCase();
else if (op == "todec") a = no_idea_how_to_do_it;
document.CalcForm.answer1.value = a;
return;
}
//-->
</script>
</head>
<body>
<h1>Hex Calculator</h1>
<form name="CalcForm">
Dec:
<input type="text" name="num1" value="" size=10>
Hex:
<input type="text" name="answer1" value="" size=10>
<p>
<input type="button" value="to Hex" OnClick="HexCalc('tohex')">
<br><br><br><br>
Hex:
<input type="text" name="num2" value="" size=10>
Dec:
<input type="text" name="answer2" value="" size=10>
<p>
<input type="button" value="to Dec" OnClick="HexCalc('todec')">
</form>
</body>
</html>
Steve
hexadecimal and vice versa. I was able to get the 'decimal to hex'
part going. But, I have no idea how to do the hex to decimal part.
Can you show me in the following sample what needs to be added?
<html>
<head>
<script language="JavaScript">
<!--
function HexCalc(op) {
var a;
var n1 = eval(document.CalcForm.num1.value);
if (op == "tohex") a = n1.toString(16).toUpperCase();
else if (op == "todec") a = no_idea_how_to_do_it;
document.CalcForm.answer1.value = a;
return;
}
//-->
</script>
</head>
<body>
<h1>Hex Calculator</h1>
<form name="CalcForm">
Dec:
<input type="text" name="num1" value="" size=10>
Hex:
<input type="text" name="answer1" value="" size=10>
<p>
<input type="button" value="to Hex" OnClick="HexCalc('tohex')">
<br><br><br><br>
Hex:
<input type="text" name="num2" value="" size=10>
Dec:
<input type="text" name="answer2" value="" size=10>
<p>
<input type="button" value="to Dec" OnClick="HexCalc('todec')">
</form>
</body>
</html>
Steve