In this C program we will calculate the XOR function between two bits(i.e: 0 or 1) and print the result, in the screen. The two bits(i.e: 0 or 1) will be taken from the user.color>
Discussion:
The XOR gate (sometimes EOR gate, or EXOR gate and pronounced as Exclusive OR gate) is a digital logic gate that gives a true (1 or HIGH) output when the number of true inputs is odd. An XOR gate implements an exclusive or; that is, a true output results if one, and only one, of the inputs to the gate is true. If both inputs are false (0/LOW) or both are true, a false output results. XOR represents the inequality function, i.e., the output is true if the inputs are not alike otherwise the output is false. A way to remember XOR is "one or the other but not both".(from Wikipedia) For full article click here.input:
The two bits(i.e. 0 or 1)output:
The XOR of the bits will be printed on the screen.CODE---->
#include
#include
color>main()
{
int bit1,bit2;
printf("Enter the 1st bit : color>");
scanf("%dcolor>",&bit1);
printf("\nPlease, Enter the 2nd bit : color>");
scanf("%dcolor>",&bit2);
if(bit1==0color>||bit1==1color>&&bit2==0color>||bit2==1color>)
{
if(bit1==bit2color>)
{
printf("\n\nThe result is %d XOR %d = 0color>",bit1,bit2);
}
else
{
printf("\n\nThe result is %d XOR %d = 1color>",bit1,bit2);
}
}
else
{
printf("\n\nSorry, You have entered wrong choice/value.color>");
}
getch();
}
color>