Bitwise exclusive OR operator (^) เปรียบเทียบบิตของ operand แรกกับบิตที่ตรงกันของ operand ที่สอง หากบิตหนึ่งเป็น 0 อีกตัวเป็น 1 บิตผลลัพธ์จะเป็น 1 มิฉะนั้นเป็น 0 ทั้งสอง operands ต้องเป็น integral types ตัวอย่าง -
ตัวอย่าง
#include <iostream>
using namespace std;
int main() {
unsigned short a = 0x5555; // pattern 0101 ...
unsigned short b = 0xFFFF; // pattern 1111 ...
cout << hex << ( a ^ b ) << endl;
}
ผลลัพธ์
aaaa
ซึ่งแทนรูปแบบ 1010...