-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase10toX.html
69 lines (65 loc) · 1.88 KB
/
base10toX.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<body>
<style>
body{
background:#111;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color:#ddd;
}
</style>
<h2>From 10 base to X base number - program by: Kun Attila</h2>
<form>
<table>
<tr>
<td><label for="num">Number (0 up to 2<sup>64</sup>-1):</label></td>
<td><input type="number" id="num" name="num" oninput="calculate(this.value, document.getElementById('numSys').value);"></td>
</tr>
<tr>
<td><label for="numSys">Number System(2-36):</label></td>
<td><input type="number" id="numSys" name="numSys" oninput="calculate(document.getElementById('num').value, this.value);"></td>
</tr>
<tr>
<td><label for="res">Result:</label></td>
<td><span id="res">Fill the inputs</span></td>
</tr>
</table>
</form>
<script>
const resTXT = document.getElementById("res");
function calculate(numb, numbSys){
if (numb > (Math.pow(2,64)-1)){
resTXT.innerHTML = "This program doesn't allow numbers greater than 2<sup>64</sup>-1";
}
else if (numb == 0){
resTXT.innerHTML = "0";
}
else if (numb < 1){
resTXT.innerHTML = "Enter a number greater than or equal to 0";
}
else if (numbSys > 36 || numbSys < 2)
{
resTXT.innerHTML = "Wrong number system entered";
}
else
{
let result = [];
let numbers = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let p = 0;
while (numb > 0)
{
result[p] = numbers[numb % numbSys];
numb = Math.floor(numb/numbSys);
p++;
}
let output = '';
for (let i = p - 1; i > -1; i--)
{
output += result[i];
}
resTXT.innerHTML = output;
}
}
</script>
</body>
</html>