toString() 方法能够以十六进制、八进制或二进制输出数
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 数字</h1>
- <p>toString() 方法以基数 2 到 36 输出字符串:</p>
- <p id="demo"></p>
- <script>
- var myNumber = 32;
- document.getElementById("demo").innerHTML =
- "32 = " + "<br>" +
- " Decimal " + myNumber.toString(10) + "<br>" +
- " Hexadecimal " + myNumber.toString(16) + "<br>" +
- " Octal " + myNumber.toString(8) + "<br>" +
- " Binary " + myNumber.toString(2);
- </script>
- </body>
- </html>