-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunction_Evaluate.java
More file actions
70 lines (65 loc) · 2.19 KB
/
Function_Evaluate.java
File metadata and controls
70 lines (65 loc) · 2.19 KB
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
70
class Function_Evaluate
{
protected static StringBuffer f1(StringBuffer v1, StringBuffer v2) // AND
{
StringBuffer res=new StringBuffer("");
for(int i=0;i<v1.length();i++)
{
if(v1.charAt(i)=='1' && v2.charAt(i)=='1') res.append("1");
else res.append("0");
}
return res;
}
protected static StringBuffer f2(StringBuffer v1, StringBuffer v2) // OR
{
StringBuffer res=new StringBuffer("");
for(int i=0;i<v1.length();i++)
{
if(v1.charAt(i)=='0' && v2.charAt(i)=='0') res.append("0");
else res.append("1");
}
return res;
}
protected static StringBuffer f3(StringBuffer v1, StringBuffer v2) // NAND
{
StringBuffer res=new StringBuffer("");
for(int i=0;i<v1.length();i++)
{
if(v1.charAt(i)=='1' && v2.charAt(i)=='1') res.append("0");
else res.append("1");
}
return res;
}
protected static StringBuffer f4(StringBuffer v1, StringBuffer v2) // NOR
{
StringBuffer res=new StringBuffer("");
for(int i=0;i<v1.length();i++)
{
if(v1.charAt(i)=='0' && v2.charAt(i)=='0') res.append("1");
else res.append("0");
}
return res;
}
protected static StringBuffer f5(StringBuffer v1, StringBuffer v2) // XOR
{
StringBuffer res=new StringBuffer("");
for(int i=0;i<v1.length();i++)
{
if(v1.charAt(i)=='1' && v2.charAt(i)=='0') res.append("1");
else if(v1.charAt(i)=='0' && v2.charAt(i)=='1') res.append("1");
else res.append("0");
}
return res;
}
protected static StringBuffer f6(StringBuffer v1, StringBuffer v2) // XNOR
{
StringBuffer res=new StringBuffer("");
for(int i=0;i<v1.length();i++)
{
if(v1.charAt(i)=='1' && v2.charAt(i)=='1') res.append("1");
else if(v1.charAt(i)=='0' && v2.charAt(i)=='0') res.append("1");
else res.append("0");
}
return res;
}
} //end of Class