Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ bitset::operator^ function is used to return a bitset which contains the result of bitwise XOR operation on given bitsets.

Syntax

template<size_t N>
  bitset<N> operator^ (const bitset<N>& lhs, 
                       const bitset<N>& rhs);
template<size_t N>
  bitset<N> operator^ (const bitset<N>& lhs, 
  	               const bitset<N>& rhs) noexcept;

Parameters

lhs Specify the first bitset object.
rhs Specify the second bitset object.

Return Value

Returns the bitset which contains the result of XOR operation.

Exception

Never throws exceptions.

Example:

In the below example, the bitset::operator^ function is used to perform bitwise XOR operation on the given bitsets.

#include <iostream>
#include <bitset>
using namespace std;
 
int main (){
  bitset<4> bset1("1001");
  bitset<4> bset2("1100");

  cout<<"bset1 is: "<<bset1;
  cout<<"\nbset2 is: "<<bset2;

  //performing bitwise XOR operation
  auto bset3 = bset1 ^ bset2;

  cout<<"\nbset1 ^ bset2 = "<<bset3;

  return 0;
}

The output of the above code will be:

bset1 is: 1001
bset2 is: 1100
bset1 ^ bset2 = 0101

❮ C++ <bitset> Library