Pages

Saturday, February 6, 2016

Use of XOR operations on two numbers using C program.

#include <stdio.h>
int main()
{
    int x, y, xor1, xor2, xor3;
 
    printf ("Number 1=");
    scanf ("%x", &x);
 
    printf ("Number 2=");
    scanf ("%x", &y);
 
    xor1 = x^y;
    printf ("XOR of x=%d and y=%d is: %x \n" ,x, y, xor1);
 
    xor2 = xor1^y;
    printf ("XOR of xor1=%d and y=%d is: %x \n" , xor1, y, xor2);
 
    xor3 = x^xor1;
    printf ("XOR of x=%d and xor1=%d is: %x \n", x, xor1, xor3);
 
    return 0;
}

Output of the program

Number 1=3
Number 2=6
XOR of x=3 and y=6 is: 5
XOR of xor1=5 and y=6 is: 3
XOR of x=3 and xor1=5 is: 6




You may also like to learn following programs:


No comments:

Post a Comment