Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> 10 hexadecimal <--> 2 hexadecimal </title>
</Head>
<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>
</Html>