MediaWiki:JS-Testing

Insert Decimal Number:  



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 + " "; figs = figs + "The octal representation of " + x + " is " + octal + " ";

document.getElementById("result").innerHTML = figs; }

This free script provided by JavaScript Kit