- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.js
More file actions
Latest commit
24 lines (23 loc) · 935 Bytes
/
Copy pathbase.js
File metadata and controls
24 lines (23 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
functionconvert(){
varcbase=document.getElementById("cbase").checked;
document.getElementById("base1").disabled=!cbase;
varcalph=document.getElementById("calph").checked;
document.getElementById("alph").disabled=!calph;
if(!cbase){
document.getElementById("base1").value="10";
}
if(!calph){
document.getElementById("alph").value="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
varstrnum=document.getElementById("num").value;
varstrbase1=document.getElementById("base1").value;
varstralph=document.getElementById("alph").value;
varstrbase2=document.getElementById("base2").value;
try{
varcur=bigInt(strnum,strbase1,stralph);
if(strbase2=="1"&&cur.compare(1000)==1){throw"Base 1 is a bad idea for big numbers";}
document.getElementById("res").innerHTML=cur.toString(strbase2,stralph);
}catch(error){
document.getElementById("res").innerHTML=error;
}
}