C/C++ code
I have the following code below, i am trying to add xnorr,norr,nandd function to it, how would i do this
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
char nott(char operand);
char andd(char operand1, char operand2);
char orr(char operand1, char operand2);
char xorr(char operand1,char operand2);
#define PREFERRED 'p'
#define OTHER 'o'
#define INVALID 'x'
char nott( char operand )
{
char result=INVALID;
if (operand == PREFERRED )
result=OTHER;
else
result=PREFERRED;
return (result);
}
char andd(char operand1, char operand2)
{
char result=INVALID;
if (operand1==PREFERRED)
{
if (operand2==PREFERRED)
{
result=PREFERRED;
}
else if (operand2==OTHER)
{
result=OTHER;
}
}
else if(operand1==OTHER)
{
if(operand2==OTHER)
{
result=OTHER;
}
else if (operand2==PREFERRED)
{
result=OTHER;
}
}
return (result);
}
char orr(char operand1, char operand2)
{
char result=0;
result=INVALID;
if (operand1 == PREFERRED)
result = PREFERRED;
else if (operand2==PREFERRED)
result = PREFERRED;
else
result = OTHER;
return (result);
}
char xorr(char operand1,char operand2)
{
char result=orr(andd(nott(operand1),operand2),andd(nott(operand2),operand1));
return(result);
}
char nandd(char operand1,char operand2)
{
char result=INVALID;
result=nott(andd(operand1,operand2));
return(result);
}
|
Topic archived. No new replies allowed.