While the suggested things are undoubtedly true, I found the answer a long while back. The behavior I am describing is actually that of a space filling Z-Curve. Simply performing a Z-curve transform will put the data into an order in which every 4 elements in order will be the desired grouping:
for i = 0:1
for j = 0:1
for x = 2*i:2*i+1
for y = 2*j:2*j+1
% repeat x and y loops for 2^n dimensions
end
end
end
end
Obviously this is not ideal for variable sizes, but you can use bitmasking math to mimic the behavior.
This causes a transform of such data to simply be 0,1,2,3 = 0,1,n,n+1 (as the first top left corner 2x2 grouping)