I think you conceptually are in a doubt with xor.

Lets say I have a xor numbers till 8 in xor(8) and numbers till 5 in xor(5).

```
xor(8)=1^2^3^4^5^6^7^8
xor(5)=1^2^3^4^5
```

Now, lets say you want xor of all numbers in range [6,8] , i.e. 6^7^8.

What does xor do? If the bits are same, it will result in 0, if the bits are different, it results in 1.

xor(5)=1 , xor(8)=8.

Their difference is 7. But whats their xor?

```
8=1000
1=0001
A=1001//A=ans=9.
```

You can see that the anser of 6^7^8 is indeed 9. Meaning, xor®^xor(l-1) can be greater than r itself, so only “^” operator should be used. You cannot replace “^” with a simple “-” or “+” sign.

(PS: I assume that @meooow 's answer already clarified the doubt of “Xor of a number with itself is always 0”)