Given a value X, the task is to find the number Y which will give maximum value possible when XOR with X.
(Assume X to be 8 bits) Maximum possible value of X and Y both is 255.
Input: X = 2 Output: 253 Binary Representation of X = 00000010 Binary Representation of Y = 11111101 Maximum XOR value: 11111111 Input: X = 200 Output: 55
Approach: In order to ensure maximum value of XOR, we need to set all those bits ON which are OFF in X. So for that, Y should have all bits ON which are OFF in X and OFF which are ON in X as (0^1 = 1 and 1^0 = 1). So Y should be the 1’s complement representation of X.
Below is the implementation of the above approach:
Required Number is : 251
- Find the maximum possible Binary Number from given string
- Maximum number of splits of a binary number
- Find the node whose xor with x gives maximum value
- Find the maximum subset XOR of a given set
- Find a sub matrix with maximum XOR
- Find maximum xor of k elements in an array
- Find triplets in an array whose AND is maximum
- Find Maximum XOR value of a sub-array of size k
- Find the maximum subarray XOR in a given array
- Find the root of the sub-tree whose weighted sum XOR with X is maximum
- Find element with the maximum set bits in an array
- Find maximum XOR of given integer in a stream of integers
- Find a number which give minimum sum when XOR with every number of array of integers
- Number whose sum of XOR with given array range is maximum
- Remove one bit from a binary number to get maximum value
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.