Convert Integer to strings

[Total: 0    Average: 0/5]

This file shows how to convert any integer into a string equivelant in any base up to and including base 36.

Body Code:

<script type=text/javascript>
var num=128
var numDec = num.toString()
var numOct = num.toString(8)
var numHex = num.toString(16)
var numBase4 = num.toString(4)
document.write('<BR><BR>Output of the code is as follows:<BR><BR></div><div class=result>')
document.writeln("num="+num+"="
                 +numDec+"<sub>10</sub>="
                 +numOct+"<sub>8</sub>="
                 +numHex+"<sub>16</sub>="
                 +numBase4+"<sub>4</sub><BR>");
// base 36 is the max
var x=0
for (var i=2;i<36;i++) {
  document.writeln(num.toString(i)+"<sub>"+i+"</sub>");
  if (!(i%5)) x = "<BR>"; else x = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  document.writeln(x);
}
document.write('</div>')
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *