C examples for Operator:Bit Operator
The bitwise XOR operator, ^, produces a 1 if both bits are different, and 0 if they're the same.
#include <stdio.h> int main(void) { /* ww w .j a va 2s .c o m*/ int x = 13; int y = 6; int z = x ^ y; // Exclusive OR the bits of x and y printf("%d",z); return 0; }
This results in z containing the value 11 (binary 1011), because the bits combine as follows:
x 0 0 0 0 1 1 0 1 y 0 0 0 0 0 1 1 0 x ^ y 0 0 0 0 1 0 1 1