the xor() function : Bitwise XOR « Data Type « C / ANSI-C






the xor() function

  

#include <stdio.h>

int xor(int a, int b);

int main(void)
{
  int p, q;

  printf("enter P (0 or 1): ");
  scanf("%d", &p);
  printf("enter Q (0 or 1): ");
  scanf("%d", &q);
  printf("P AND Q: %d\n", p && q);
  printf("P OR Q: %d\n", p || q);
  printf("P XOR Q: %d\n", xor(p, q));

  return 0;
}

int xor(int a, int b)
{
  return (a || b) && !(a && b);
}

           
       








Related examples in the same category

1.Perform a logical XOR operation using the two arguments
2.Bitwise calculationBitwise calculation