README.md

December 4, 2022 ยท View on GitHub

Hex & Decimal Conversion

Description

Convert numbers from Hex to Decimal and from Decimal to Hex.

More Info

Pass values to the functions:

Hex2Dec()

Dec2Hex()

Converted Hex/Decimal value..

Submitted On
ByNick Radford
LevelBeginner
User Rating5.0 (10 globes from 2 users)
Compatibility
CategoryCalculators & Science
WorldJava
Archive File

Source Code

<html>
<head>
<title>Hex & Decimal Conversion</title>
<script language="javascript">
<!--
function Hex2Dec(HexVal) {
	var HexVal = HexVal.toUpperCase();
	return parseInt(HexVal,16);
}
function Dec2Hex(DecVal) {
	var HexChars = '0123456789ABCDEF';
	var HexStr = ''
	while (DecVal>0){
		var HexStr = HexChars.charAt( DecVal%16 ) + HexStr;
		var DecVal = Math.floor(DecVal/16);
	}
	return HexStr
}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<form name="ConvertIt">
	<table cellpadding="2" cellspacing="0" border="0">
	<tr>
		<td>Decimal Value</td>
		<td><input type="text" name="DecValue" size="10"></td>
		<td><input type="button" value="Convert to HEX" onclick="alert( Dec2Hex(document.ConvertIt.DecValue.value) )"></td>
	</tr>
	<tr>
		<td colspan="3">&nbsp;</td>
	</tr>
	<tr>
		<td>HEX Value</td>
		<td><input type="text" name="HexValue" size="10"></td>
		<td><input type="button" value="Convert to Decimal" onclick="alert( Hex2Dec(document.ConvertIt.HexValue.value) )"></td>
	</tr>
	</table>
</form>
</body>
</html>