

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find a value whose XOR with given number is maximum in C++
In this tutorial, we are going to write a program that finds the number whose XOR operation with the given number is maximum.
We are assuming the number of bits here is 8.
The XOR operation of different bits gives you the 1 bit. And the XOR operation between the same bits gives you the 0 bit.
If we find the 1's complement of the given number, then that's the number we are looking for.
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; int findNumberWithMaximumXOR(int X) { return ((1 << 8) - 1) ^ X; } int main() { int X = 4; cout << findNumberWithMaximumXOR(X) << endl; return 0; }
Output
If you run the above code, then you will get the following result.
251
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Questions & Answers
- Find the Number Whose Sum of XOR with Given Array Range is Maximum using C++
- C++ Program to find Number Whose XOR Sum with Given Array is a Given Number k
- Find the Number of Unique Triplets Whose XOR is Zero using C++
- Count smaller numbers whose XOR with n produces greater value in C++
- Find maximum XOR of given integer in a stream of integers in C++
- Maximum XOR value in matrix in C++
- Find the node whose absolute difference with X gives maximum value in C++
- Find Maximum XOR value of a sub-array of size k in C++
- Find a pair from the given array with maximum nCr value in C++
- Find a pair from the given array with maximum nCr value in Python
- C program to find out the maximum value of AND, OR, and XOR operations that are less than a given value
- Program to find number of sublists whose sum is given target in python
- Maximum XOR value of a pair from a range in C++
- Maximum Primes whose sum is equal to given N in C++
- Find the sublist with maximum value in given nested list in Python
Advertisements