Este es el código:
Código:
<html> <head> <SCRIPT LANGUAGE="JavaScript"> function GetNumber1(form) { var i = ""; var v = ""; var g = 0; var m = 0; var nUpower = 0; var nSprod = 0; var pw3 = parseInt(form.txtNumbe2.value, 10) var sNumber = stripBad2(form.txtNumber.value); var j = sNumber.length for (k=0; k < j; k++) { i = sNumber.charAt(k) nUpower = k+1 nSprod = Math.pow(pw3, -nUpower) m=i*nSprod g = g+m v = "" + g var vj = v.length var jv = v.substring(1, vj) } form.txtResult.value= jv } function GetNumber2(form) { var pw3 = parseInt(form.txtNumbe2.value, 10) var sNumber = parseFloat(stripBad(form.txtNumber.value)); var toHex=sNumber.toString(pw3); toHex=toHex.toUpperCase() form.txtResult.value= toHex} function GetNumber2a(form) { var pw3 = parseInt(form.txtNumbe2.value, 10) var sNumber = parseInt(form.txtNumber.value, pw3); sNumber = gesult(sNumber) form.txtResult.value= sNumber} function GetNumber3(form) { var frb3 = parseInt(form.txtNumbe2.value, 10) var frn3 = parseInt(form.txtNumber.value, frb3) var tob3 = parseInt(form.txtNumbe3.value, 10) if ((frb3 < 2) || (frb3 > 36)) { form.txtResult.value= "Base Number may not be greater than 36 or less than 2"} else if ((tob3 < 2) || (tob3 > 36)) { form.txtResult.value= "Base Number may not be greater than 36 or less than 2"} else { var toHex=frn3.toString(tob3); toHex=toHex.toUpperCase() form.txtResult.value= toHex + " Base " + tob3} } function GetNumber4(form) { var iz = ""; var v = ""; var pos = 0; var g = 0; var m = 0; var nUpower = 0; var nSprod = 0; var lst = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" var pw3 = parseInt(form.txtNumbe2.value, 10) var sNumber = form.txtNumber.value; sNumber = sNumber.toUpperCase() sNumber = stripBad3(sNumber) var j = sNumber.length for (k=0; k < j; k++) { iz = sNumber.charAt(k) pos = lst.indexOf(iz) nUpower = k+1 nSprod = Math.pow(pw3, -nUpower) m=pos*nSprod g = g+m v = "" + g var vj = v.length var jv = v.substring(1, vj) } form.txtResult.value= jv } function GetNumber5(form) { <!-- 1 603 + 57 602 + 46 60 + 40 = 424000 1,57,46,40 in Babylonian numerals sexagesimal --> var pw3 = parseInt(form.txtNumbe2.value, 10); var sNumber = parseFloat(stripBad(form.txtNumber.value)); drust = tobab(pw3,sNumber); form.txtResult.value= drust} function GetNumber6(form) { var pw3 = parseInt(form.txtNumbe2.value, 10) var sNumber = form.txtNumber.value; nsum = frombab(pw3,sNumber); var cNumbe3 = gesult(nsum); form.txtResult.value= cNumbe3 } function GetNumber7(form) { var pw3 = parseInt(form.txtNumbe2.value, 10) var sNumber = form.txtNumber.value; var pw4 = parseInt(form.txtNumbe3.value, 10) nsum = frombab(pw3,sNumber); drust = tobab(pw4,nsum); form.txtResult.value= drust } function frombab(pw3,sNumber) { var phrase =""; var wds = new Array(20) var dial2 = ""; var rest2 = 0; var r = 0; var bz = ","; phrase = sNumber; dial2 = phrase + ",zzz" var puzz = 0; phrase=phrase.split(','); for (z=0; z<phrase.length; z++) {if (phrase[z].length > 0) r++;} puzz = r; for (zy=0; zy<puzz; zy++) { var lbz = dial2.length; var zb2 = dial2.indexOf(bz); wds[zy] = dial2.substring(0, zb2); dial2 = dial2.substring(zb2+1, lbz); rest2 = rest2 + 1; } var tow4 = rest2 - 1; var nsum = 0; for (i = 0; i < rest2; i++) { nsum = nsum + (wds[i] * Math.pow(pw3, tow4)); tow4 = tow4 - 1; } return nsum; } function tobab(pw3,sNumber) { var tag = 0; var drust = ""; var num1 = sNumber - Math.pow(pw3, tag); while (num1 >= 0) {tag = tag + 1; num1 = sNumber - Math.pow(pw3, tag); } var tow4 = tag - 1; var sumleft = sNumber; for (i = 1; i < tag; i++) { var dig1 = Math.floor(sumleft / Math.pow(pw3, tow4)); drust = drust + dig1 + ","; sumleft = sumleft - (dig1 * Math.pow(pw3, tow4)); tow4 = tow4 - 1; } drust = drust + sumleft; return drust; } function stripBad(string) { for (var i=0, output='', valid="eE-0123456789."; i<string.length; i++) if (valid.indexOf(string.charAt(i)) != -1) output += string.charAt(i) return output; } function stripBad2(string) { for (var i=0, output='', valid="eE-0123456789"; i<string.length; i++) if (valid.indexOf(string.charAt(i)) != -1) output += string.charAt(i) return output; } function stripBad3(string) { for (var i=0, output='', valid="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; i<string.length; i++) if (valid.indexOf(string.charAt(i)) != -1) output += string.charAt(i) return output; } function gesult(ff){ if (Number.prototype.toFixed) { ff = ff.toFixed(5); ff = parseFloat(ff); } else { var leftSide = Math.floor(ff); var rightSide = ff - leftSide; ff = leftSide + Math.round(rightSide *1e+14)/1e+14; } return comma(ff); } function comma(num) { var n = Math.floor(num); var myNum = num + ""; var myDec = "" if (myNum.indexOf('.',0) > -1){ myDec = myNum.substring(myNum.indexOf('.',0),myNum.length); } var arr=new Array('0'), i=0; while (n>0) {arr[i]=''+n%1000; n=Math.floor(n/1000); i++;} arr=arr.reverse(); for (var i in arr) if (i>0) while (arr[i].length<3) arr[i]='0'+arr[i]; return arr.join() + myDec; } </SCRIPT> </head> <body > <FORM> <INPUT TYPE="text" NAME="txtNumbe2" SIZE=4 value="10"> <INPUT TYPE="text" NAME="txtNumber" SIZE=40 value="1545452455"> <INPUT TYPE="text" NAME="txtNumbe3" SIZE=4 value="16"> <INPUT TYPE="button" VALUE="Click to Convert" onclick="GetNumber7(this.form)"> <INPUT TYPE="text" NAME="txtResult" SIZE=40 > </FORM> <BR> <FORM> <INPUT TYPE="text" NAME="txtNumbe2" SIZE=4 value="10"> <INPUT TYPE="text" NAME="txtNumber" SIZE=40 value="1478675"> <INPUT TYPE="text" NAME="txtNumbe3" SIZE=4 value="16"> <INPUT TYPE="button" VALUE="Click to Convert" onclick="GetNumber7(this.form)"> <INPUT TYPE="text" NAME="txtResult" SIZE=40> </FORM> </body> </html>