1 // Test logical and bitwise AND and OR
2
test(int x,int y)3 int test(int x, int y) {
4 int v = x || y;
5 return v;
6 }
7
test2(int x,int y)8 int test2(int x, int y) {
9 if(x | y) {
10 return 1;
11 } else {
12 return 0;
13 }
14 }
15
test3(int x,int y)16 int test3(int x, int y) {
17 int v = x && y;
18 return v;
19 }
20
test4(int x,int y)21 int test4(int x, int y) {
22 if(x & y) {
23 return 1;
24 } else {
25 return 0;
26 }
27 }
28
main(int index)29 int main(int index)
30 {
31 int x,y;
32 printf("testing...\n");
33 int totalBad = 0;
34 for(y = 0; y < 2; y++) {
35 for(x = 0; x < 2; x++) {
36 int a = test(x,y);
37 int b = test2(x,y);
38 if (a != b) {
39 printf("Results differ: OR x=%d y=%d a=%d b=%d\n", x, y, a, b);
40 totalBad++;
41 }
42 a = test3(x,y);
43 b = test4(x,y);
44 if (a != b) {
45 printf("Results differ: AND x=%d y=%d a=%d b=%d\n", x, y, a, b);
46 totalBad++;
47 }
48 }
49 }
50 printf("Total bad: %d\n", totalBad);
51 return 0;
52 }
53
54