Last Update:2017-08-24
Source: Internet
Author: User
Keywords
Web page production
Ajax
javascript
In JavaScript, use the ToString () and parseint () functions to convert numbers into the system!
<! 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 <-->2 system </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 ();" /> &NBSP;<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; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP} b.value = (parseint (num)). toString (2); &NBSP} function todecimal () { var num = B.value; if (isNaN (num) | | !num) { b.value = "" return false; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP} &NBSP;&NBSp; d.value = parseint (NUM,&NBSP;2); &NBSP} </script> </body> </html>