^ (binary XOR) operator in c.


Binary XOR Operator copies the bit if it is set in one operand but not both.




Consider the following program:


#include<stdio.h>
int main()
{   int i,j,k;
 i=11^5;
 j=12^3;
 k=15^4;
 printf("\n%d\n%d\n%d",i,j,k);
    }

output:
 14
 15
 11


Explanation:

i=11^5
converting to binary
i=1011^0101=1110
1110 in decimal is 14
so i=14

j=12^3
converting to binary
i=1100^0011=1111
1111 in decimal is 15
so j=15

i=15^4
converting to binary
i=1111^0100=1011
1011 in decimal is 11
so i=11





Share on Google Plus

About Jaya Ram Myneni

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment