butterprim

Integer to Binary converter

Apr 3rd, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <html>
  2. <head>
  3. <!-- attempts at javascript by lizette -->
  4. <title>Javascript test</title>
  5. <script type="text/javascript">
  6. function convert(){
  7. var num = document.getElementById("numberBox");
  8. var str = document.getElementById("stringBox");
  9. var x = 0;
  10. var y = "";
  11. x = parseInt(num.value);
  12. y = x.toString(2);
  13. if(y == "NaN"){
  14. y = "Not an integer.";
  15. }
  16. str.value = y;
  17. }
  18. </script>
  19. <style>
  20. #wrap{
  21. position: relative;
  22. }
  23. #content{
  24. margin: 0 auto;
  25. width: 300px;
  26. height: 100px;
  27. margin-top: 200px;
  28. font-family: Calibri, Arial;
  29. font-size: 12px;
  30. }
  31. h1{
  32. font-weight: normal;
  33. margin: 0;
  34. padding: 0;
  35. margin-bottom: 5px;
  36. font-size: 15px;
  37. }
  38. input{
  39. font-family: Calibri, Arial;
  40. font-size: 12px;
  41. width: 145px;
  42. }
  43. p{
  44. margin-left: 20px;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div id="wrap">
  50. <div id="content">
  51. <h1>Integer to Binary Converter</h1>
  52. <p>
  53. Input the integer on the left textbox. <br>
  54. Make sure that it really is an integer. <br>
  55. Doubles will be converted to its floor.
  56. </p>
  57. <input type="text" id="numberBox" value="0" onchange="convert()"> <input type="text" value="0" id="stringBox" readonly>
  58. </div>
  59. </div>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment