<div class="codetitle"> <span><a style="CURSOR: pointer" data="9394" class="copybut" id="copybut9394" onclick="doCopy('code9394')"><u>复代码码</u></a></span> 代码如下:</div> <div class="codebody" id="code9394"> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 전환//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><html xmlns="http://www.w3.org/1999/xhtml"> <br><머리> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <br><title>10进제2进제</title> <br></head> <br><br><본문> <br>십진수: <br> <input type="text" id="decimal" /> <br> <input type="button" value="to Binary" onclick="return toBinary();" /> <br /> <br>바이너리: <br> <input type="text" id="binary" /> <br> <input type="button" value="to Decimal" onclick="return toDecimal();" /> <br><br> <br><script type="text/javascript"> <br>var d = document.getElementById('decimal'); <br>var b = document.getElementById('binary'); <br><br>function toBinary() { <br> var num = d.value; <br> if (isNaN(num) || !num) { <br> d.value = ""; <br> false를 반환합니다. <br> } <br> b.value = (parseInt(num)).toString(2); <br>} <br><br>function toDecimal() { <br> var num = b.value; <br> if (isNaN(num) || !num) { <br> b.value = ""; <br> false를 반환합니다. <br> } <br> d.value =parseInt(num, 2); <br>} <br></script> <br></body> <br></html> <br> </div>