# What is Bitwise XOR in C++?

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

The bitwise exclusive OR operator (^) compares every bit of} its 1st operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. Both operands to the bitwise exclusive OR operator must be of integral types. For example,

## Example

#include <iostream>
using namespace std;

int main() {
unsigned short a = 0x5555;      // pattern 0101 ...
unsigned short b = 0xFFFF;      // pattern 1111 ...
cout  << hex << ( a ^ b ) << endl;
}

## Output

This gives the output −

aaaa

Which represents the pattern 1010...

Updated on 11-Feb-2020 07:23:15