answersLogoWhite

0


Best Answer

I do not believe this is possible. The only solution I could come up with does not involve either OR or NOT, but it does use the plus and minus operators combined with the logical AND operator (more formally termed addition modulo 2, or addition without carry). The following C++ program demonstrates that the function, XOR(), correctly emulates the logical XOR operator (^).

#include

int XOR( int x, int y )

{

return(( x + y ) - ( x & y ) - (x & y ));

}

int main()

{

int x, y;

std::cout << "Truth table for 0 and 1:\n" << std::endl;

std::cout << "x y ^ XOR" << std::endl;

for( x=0; x<=1; ++x )

for( y=0; y<=1; ++y )

std::cout << x << " " << y << " " << (x^y) << " " << XOR( x,y ) << std::endl;

std::cout << std::endl;

std::cout << "Evaluation of values 0 to 4:\n" << std::endl;

std::cout << "x\ty\t^\tXOR" << std::endl;

for( x=0; x<=4; ++x )

for( y=0; y<=4; ++y )

std::cout << x << "\t" << y << "\t" << (x^y) << "\t" << XOR( x,y ) << std::endl;

std::cout << std::endl;

return(0);

}

Output

Truth table for 0 and 1:

x y ^ XOR

0 0 0 0

0 1 1 1

1 0 1 1

1 1 0 0

Evaluation of values 0 to 4:

x y ^ XOR

0 0 0 0

0 1 1 1

0 2 2 2

0 3 3 3

0 4 4 4

1 0 1 1

1 1 0 0

1 2 3 3

1 3 2 2

1 4 5 5

2 0 2 2

2 1 3 3

2 2 0 0

2 3 1 1

2 4 6 6

3 0 3 3

3 1 2 2

3 2 1 1

3 3 0 0

3 4 7 7

4 0 4 4

4 1 5 5

4 2 6 6

4 3 7 7

4 4 0 0

As you can see, the third and fourth columns are all equal, thus proving the function correctly emulates the logical XOR for values 0 to 4. The same is true for all permutations of x and y.

Note that while it is possible to use AND, OR and NOT when both x and y are guaranteed to be in the range 0 to 1 (and therefore capable of producing the truth table shown above), the function does not correctly emulate the XOR operator when x or y is neither 0 nor 1. You can test this by swapping the XOR function above with the following implementation:

int XOR( int x, int y )

{

return(( x | y ) & !( x & y ));

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you write a CPP program to displaying XOR truth table using logical AND OR and NOT?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are tables of logic?

A table of logic, or truth table, lists the possible combination of truth values for boolean (logical, two-valued) variables.


Define a truth table?

A truth table is usually a table in which the truth or falsehood of two variables are taken as input and these form the edges of the table. The content of the table shows the truth value of the result of some operation on the variables.


Difference between truth table and excitation table?

truth table contains inputs and excitation table takes outputs as inputs


What is a truth table evaluator?

A truth table evaluator is a computer program that evaluates a truth table, i.e., it produces the truth value of a statement for all possible values of its variables. There are at least a few on the web: Brian Borowski's TT Constructor (http://www.brian-borowski.com/index.html) Joole (http://stephan-brumme.com/programming/Joole/) Orion Transfer TT Evaluator (http://svn.oriontransfer.org/TruthTable/) Lawrence Turner's TT Evaluator (http://turner.faculty.swau.edu/mathematics/materialslibrary/truth/)


What is a negation?

Negation is a logical connective. In philosophy, it means that it takes truth to a falsehood, and falsehood to a truth.


Is logical necessary truth examples of posteriori knowledge?

yes


what is the correct truth table for p V -q?

what is the correct truth table for p V~ q


A B C ' A'B'C' by using truth table?

(A+B+C)' = A'B'C' by using truth table


Is this the truth?

This is a logical fallacy. That's like asking "What is the smell of the color nine?" Your asking if a question is the truth, when the question is asking for a truth and makes no assertions about the truth.


When using a truth table 1 and 1 equal what?

As inputs to the truth table 1 and 1 signify that they are both true. The output will depend on what kind of truth table we are talking about, AND, OR, XOR, etc.


Difference between excitation table and truth table?

truth table gives relation between i/p &amp; o/p. excitation table is use for design of ff &amp; counters.


What is a table organizing the input rule and the output of a function?

If it is boolean logic, typically that is called a Truth Table.