Does anyone knows how to write java script to convert binary number to decimal n
ID: 3623329 • Letter: D
Question
Does anyone knows how to write java script to convert binary number to decimal number or vise verse?Explanation / Answer
Dear... script type = "text/javascript"> function dec2bin() { var x = document.getElementById("deci").value; if ((/[^0-9]/g.test(x)) || x == "") { alert ("You must enter an integer decimal number!"); document.getElementById("deci").value = ""; document.getElementById("deci").focus(); return false; } x = parseInt(x); var bin = x.toString(2); var hex = x.toString(16).toUpperCase(); var octal = x.toString(8); var figs = "The binary representation of " + x + " is " + bin + ""; figs = figs + "The hexadecimal representation of " + x + " is " + hex + "
"; document.getElementById("result").innerHTML = figs; }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.