std::bit_xor in C++ with Examples Last Updated : 01 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The bit_xor is an inbuilt function in C++ which is used to perform bitwise_xor and return the result after applying the bitwise_xor operation on it's arguments. Header File: #include <functional.h> Template Class: template <class T> struct bit_xor; Parameters: It accepts a parameter T which is the type of the argument to be compared by the functional call. Note: Objects of this class can be used on standard algorithms such as transform or accumulate. Member functions ( 'operator()' ) returns the bit_xor of its arguments. We must include the library 'functional' and 'algorithm' to use bit_xor and transform() respectively. Below is the illustration of bit_xor in C++: Problem 1: CPP // C++ program to illustrate bit_xor in C++ #include <algorithm> #include <functional> // to include bit_xor #include <iostream> #include <iterator> using namespace std; int main() { // declaring the values int A[] = { 1, 2, 3, 4, 5, 6 }; int B[] = { 6, 7, 8, 4, 5, 0 }; int n = 6; // defining result int result[n]; // transform is used to apply bitwise_xor // on the arguments A and B transform(A, end(A), B, result, bit_xor<int>()); // printing the resulting array cout << "A xor B = "; for (const int& answer : result) cout << ' ' << answer; return 0; } Output: A xor B = 7 5 11 0 0 6 Program 2: CPP // C++ program to illustrate bit_xor in C++ #include <algorithm> #include <functional> #include <iostream> #include <iterator> using namespace std; int main() { // declaring the values int A[] = { 0, 0xff, 15, 22 }; int B[] = { 1, 255, 0xfa, 0x16 }; int n = 4; // defining result int result[n]; // transform is used to apply bitwise_xor // on the arguments A and B transform(A, end(A), B, result, bit_xor<int>()); // printing the resulting array cout << "A xor B = "; for (const int& answer : result) cout << ' ' << answer; return 0; } Output: A xor B = 1 0 245 0 Reference: https://en.cppreference.com/w/cpp/utility/functional/bit_xor Comment More infoAdvertise with us Next Article std::bit_xor in C++ with Examples H harshit_chari Follow Improve Article Tags : C++ Programs C++ Write From Home Bitwise-XOR CPP-Functions +1 More Practice Tags : CPP Similar Reads Binary literals in C++14 with Examples In this article, we will discuss Binary literals in C++14. While writing programs which involve mathematical evaluations or various types of number, we usually like to specify each digit type with specific prefix i.e., For Hexadecimal number use the prefix '0x' and for Octal number use the prefix '0 2 min read How to Create Stack of Bitset in C++? In C++, a stack is a container adapter that provides a last-in, first-out (LIFO) type of data structure with two major operations, namely push and pop while Bitset is a container that can store N bits and provides constant-time operations to manipulate individual bits. In this article, we will learn 2 min read How to Set, Clear, and Toggle a Single Bit in C++? In bit manipulation, setting a bit, clearing a bit, and toggling a single bit are basic operations. We can easily carry out these operations using the bitwise operators in C++. In this article, we will see how to set, clear, and toggle operations on the Kth bit. Example Input: N = 15, K = 0Output: S 3 min read How to Use Bit Manipulation Methods in C++ Bit manipulation is a technique used for optimizing performance and memory usage in various programming scenarios. It is very useful from a Competitive Programming point of view. In this article, we will learn how we can use bit manipulation methods in C++ and provide examples to help you understand 5 min read bitset count() in C++ STL bitset::count() is an inbuilt STL in C++ which returns the number of set bits in the binary representation of a number. Syntax: int count() Parameter: The function accepts no parameter. Return Value: The function returns the number of set bits. It returns the total number of ones or the number of se 2 min read Like