C program using bitwise XOR(^)

EX: write a C program to perform XOR operation of two intiger's. How to write a C program to perform XOR operation of two intiger's. C program to perform XOR operation of two intiger's.

Input from user:

a=13 , b=24;

Expected Output:

After performing XOR operation the output is: 21






  Logic to perform XOR operation of two intiger's:


 Firstly you need to know how work XOR operator.


 Note: The result of XOR is 1 if the two bits are different.

1. We take two intiger numbers a=13 and b=24.

 2. Binary representation of a XOR b is-


      a      = 0000 1101

      b      = 0001 1000
------------------------------------
      a|b   = 0001 0101 =21

3. After performing XOR operation 8 bit binary representation is 0001 0101 which is 21 in decimal.


4. So output of the program is  21.




  C program using bitwise XOR :


#include<stdio.h>
void main()
{
int a=13,b=24;

printf("After performing XOR operation the output is:%d",a^b);

}


Above program shows the following output:


C program using bitwise XOR operator, C program using bitwise XOR

No comments:

Post a Comment

If you have any doubts, please discuss here...👇