-
-
Save lifuzu/9beb0a1b9e6a4e3e384a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>DecHex Convertor/Calculator</title> | |
<script type="text/javascript"> | |
function dec2hex(dec) { | |
return (parseInt(dec)).toString(16); | |
} | |
function hex2dec(hex) { | |
return parseInt(hex, 16); | |
} | |
function hexadd(h1, h2) { | |
return dec2hex(hex2dec(h1) + hex2dec(h2)); | |
} | |
</script> | |
</head> | |
<body> | |
<form> | |
<input type="text" name="source" placeholder="Please enter number."> | |
<input type="text" name="target" placeholder="You should get result here"><br> | |
<input type="radio" name="orient" value="dec2hex" checked="checked">Decimal to Hex</input><br> | |
<input type="radio" name="orient" value="hex2dec">Hex to Decimal</input><br> | |
<input type="button" value="Submit" onclick="if (orient.value=='dec2hex') {target.value=dec2hex(source.value)} else {target.value=hex2dec(source.value)}"> | |
<input type="button" value="Clear" onclick="source.value=''; target.value=''"> | |
<input type="button" value="Add" onclick="target.value=hexadd('F', 'A')"> | |
</form> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment