title: Find XOR of all numbers in a given range
body: <p>You are given a large range [a,b] where 'a' and 'b' can be typically between 1 and 4,000,000,000 inclusive. You have to find out the XOR of all the numbers in the given range.</p>
  <p>This problem was used in TopCoder SRM. I saw one of the solutions submitted in the match and I'm not able to figure out how its working.</p>
  <p>Could someone help explain the winning solution:</p>
  <pre class="lang-c prettyprint-override"><code>long long f(long long a) {
       long long res[] = {a,1,a+1,0};
       return res[a%4];
  }
  
  long long getXor(long long a, long long b) {
       return f(b)^f(a-1);
  }
  </code></pre>
  <p>Here, <code>getXor()</code> is the actual function to calculate the xor of all number in the passed range [a,b] and &quot;f()&quot; is a helper function.</p>