Can I simplify successive XOR operations?
Yes, there are ways to improve the efficiency greatly.



Let ${}_k{i}$ be the $k$-th digit of $i$ in binary representation, i.e., it is 0 if $\lfloor i/2^k\rfloor$ is even and 1 otherwise. For example, since $19=(10011)_2$, $_019=1$, $_119=1$, $_219=0$, $_319=0$, $_419=1$. In most programming languages,  ${}_k{i}$ can be computed as $(i\text{&gt;&gt;}k)\%2$.

Let us apply the power of summand splitting and rearrangement to inspect the contribution to the sum by the $k$-th digits in isolation.

$$\begin{aligned}
\text{total sum}
&amp;=\sum_{\text{ row } i\,}\sum_{\text{ column }j\,} i \oplus j\\
&amp;=\sum_{\text{ row } i\,}\sum_{\text{ column }j\,} \sum_{0\le k\lt u} ({}_k{i}\oplus {}_k{j})\cdot 2^k\\
&amp;=\sum_{0\le k\lt u} 2^k\sum_{\text{ row } i\,}\sum_{\text{ column }j\,} {}_k{i}\oplus {}_k{j}\\
&amp;=\sum_{0\le k\lt u} 2^k\left(\#\{\text{row }i\mid {}_k{i}=1\}\cdot \#\{\text{column }j\mid {}_k{j}=0\}\right.\ + \\
&amp;\quad\quad\left.\#\{\text{row }i\mid {}_k{i}=0\}\cdot \#\{\text{column }j\mid {}_k{j}=1\}\right)
\end{aligned}$$

We can set $u=\lceil\log_2\max(m+1, n+1)\rceil$ or any integer such that $n,m\lt 2^u$, where $n$ is the number of rows and $m$ is the number of columns. If $m$ and $n$ are ints or longs in Java or C#, $u=63$ could be a good choice.

Now the problem is shifted to compute $\#\{\text{row }i\mid {}_k{i}=0\}$ and the like ones. We have
$$\begin{aligned}
\#\{\text{row }i\mid {}_k{i}=0\}
&amp;=2^k\left\lfloor\frac {n-1}{2^{k+1}}\right\rfloor +
\min\left(n-2^{k+1}\left\lfloor\frac{n-1}{2^{k+1}}\right\rfloor,\ 2^k\right)\\
\#\{\text{row }i\mid {}_k{i}=1\}
&amp;=2^k\left\lfloor\frac{n-1}{2^{k+1}}\right\rfloor + 
\max\left(0,\ n-2^{k+1}\left\lfloor\frac{n-1}{2^{k+1}}\right\rfloor -2^k\right)
\end{aligned}$$
In terms of Java, they are, respectively,

((n-1)&gt;&gt;(k+1)&lt;&lt;k) + Math.min(1&lt;&lt;k, n - ((n-1)&gt;&gt;(k+1)&lt;&lt;(k+1))),
((n-1)&gt;&gt;(k+1)&lt;&lt;k) + Math.max(0, n - ((n - 1)&gt;&gt;(k+1)&lt;&lt;(k+1)) - (1&lt;&lt;k))


The time-complexity of the algorithm is about $O((\log n)^2)$