You can calculate the value of an order z curve using the following code:
uint32_t calcZOrder(uint16_t xPos, uint16_t yPos) { static const uint32_t MASKS[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF}; static const uint32_t SHIFTS[] = {1, 2, 4, 8}; uint32_t x = xPos;
It was taken from here. Tweedling Hacks Bit
From your 128x128 array (or any other size) you can easily calculate the zz curve value from any position. For instance:
xPos = 2, yPos = 3 -> z order curve value = 7
The maximum array size for the example code is 65536 * 65536. Just use power 2 for convenience, in this case the maximum space is wasted for approx. 3/4
source share