^ (Exclusive Or) Operator - C++ Operator

C++ examples for Operator:Bit Operator

Introduction

The exclusive or operator sets the resulting bit to true when either the left or the right bit is set, not when both are set and not when neither are set.

Demo Code

#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int leftBits{ 0x00011000 };
    int rightBits{ 0x00010100 };
    cout << showbase << hex;
    cout << "Result of 0x00011000 ^ 0x00010100: " << (leftBits ^ rightBits) << endl;
    cout << "Result of 0x00011000 ^ 0x11100111: " << (leftBits ^ ~leftBits) << endl;

    return 0;/*from w w w . j a v  a  2  s  . c  om*/
}

Result


Related Tutorials