Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>10 <-->2 System </title>
<body>
Decimal:
<input type= "text" id= "decimal"/>
<input type= "button" value= "to Binary" onclick= "return tobinary ();/> <br
Binary:
<input type= "text" id= "binary"/>
<input type= "button" value= "to Decimal" onclick= "return ToDecimal ();"/>
<script type= "Text/javascript" >
var d = document.getElementById (' decimal ');
var B = document.getElementById (' binary ');
function Tobinary () {
var num = D.value;
if (isNaN (num) | |!num) {
D.value = "";
return false;
}
B.value = (parseint (num)). toString (2);
}
function ToDecimal () {
var num = B.value;
if (isNaN (num) | |!num) {
B.value = "";
return false;
}
D.value = parseint (num, 2);
}
</script>
</body>