-
Notifications
You must be signed in to change notification settings - Fork 0
/
xor.js
46 lines (42 loc) · 1.62 KB
/
xor.js
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
let calc = document.getElementById("calculate");
calc.onclick = function () {
let input_type = document.getElementsByClassName("t")[0].value;
let input_type2 = document.getElementsByClassName("t")[1].value;
let output_type = document.getElementsByClassName("t")[2].value;
var n1 = document.getElementById("first").value;
var n2 = document.getElementById("second").value;
if (input_type != input_type2) {
document.getElementById("output").value = "Syntax Error";
document.getElementById("output").style.backgroundColor = "red";
document.getElementById("output").style.color = "white";
} else {
document.getElementById("output").style.backgroundColor = "white";
document.getElementById("output").style.color = "black";
if (input_type == 2) {
n1 = parseInt(n1, 2);
n2 = parseInt(n2, 2);
} else if (input_type == 8) {
n1 = parseInt(n1, 8);
n2 = parseInt(n2, 8);
} else if (input_type == 10) {
n1 = parseInt(n1, 10);
n2 = parseInt(n2, 10);
} else if (input_type == 16) {
n1 = parseInt(n1, 16);
n2 = parseInt(n2, 16);
}
/************************************************************ Output *********************************************************/
let ans = n1 ^ n2;
let final_output;
if (output_type == 2) {
final_output = ans.toString(2);
} else if (output_type == 8) {
final_output = ans.toString(8);
} else if (output_type == 10) {
final_output = ans.toString(10);
} else if (output_type == 16) {
final_output = ans.toString(16);
}
document.getElementById("output").value = final_output;
}
};