here is the code that implements the xor gate for my program...
public static boolean xor(boolean... input) //for n inputs
{
boolean result=input[0]; //assigns 1st value to result
for(int i=0; i<input.length-1;) //loops till length-1
{
result=(result&&!input[i+1])||(!result&&input[i+1]); //does A*B'+A'*B
i++;
}
return result;
}
the code gives the right output for 3 inputs...
now here is the code that implements the xnor gate.
public static boolean xnor(boolean... input) //for n inputs
{
boolean result=input[0]; //assigns 1st value to result
for(int i=0; i<input.length-1;) //loops till length-1
{
result=(result&&input[i+1])||((!result)&&(!input[i+1])); //does A*B+A'*B'
i++;
}
return result;
}
the output of this for a given set of input should be exactly the opposite of the output of xor gate. however, the output comes out to be the same!
i have checked my code several times and its all right. infact if i replace the above code with the following the output turns out to be fine...
public static boolean xnor(boolean... input) //for n inputs
{
return(!XOR.xor(input));
}
any help?