Blaize11's blog

By Blaize11, history, 3 years ago, In English

In case you are asked to find out the Number which gives minimum and maximum upon XORing with a given number. The concept is simple.

  1. The minimum XOR result is 0, so the number which produces minimum result upon XOR with a given Number is the Number itself.
  2. The number which produces the maximum XOR is the given number with all its bits flipped.

Bit Flipping LOgic: 1. Find The number of bit. 2. For each of the bits, transverse once and flip the bits.

The C++ code for flipping is:

int flip(int num) { int x=log2(num)+1; // Finding the number of bits for(int i=0; i<x; i++) num=num^(1<<i); // Flipping Each bits of the given number by XORing with the present bit

return num; }

Full text and comments »

  • Vote: I like it
  • -18
  • Vote: I do not like it