Z-order (Morton code) calculator

Morton code
—

Interleaves the bits of x and y (bit 0 of x, bit 0 of y, bit 1 of x, ...) into a single number. Coordinates close together in 2D space are usually close together in the resulting order too, which is why spatial indexes and quadtrees use it to turn 2D range queries into mostly-contiguous 1D scans.


What a Morton code is

A Morton code, also called a Z-order curve value, maps a multi-dimensional coordinate to a single number by interleaving the bits of each dimension - bit 0 of x, then bit 0 of y, then bit 1 of x, then bit 1 of y, and so on. The result has a useful property: coordinates that are close together in 2D space are usually close together in the resulting one-dimensional Morton order too, which is why spatial databases, quadtrees and geohash-style systems use it to turn 2D range queries into mostly-contiguous 1D range scans.

Encode and decode

Enter x and y (up to 16 bits each, so the interleaved result fits in 32 bits) to get the Morton code, or enter a Morton code to split it back into its x and y bit streams - shown in binary alongside the interleaved result, so the bit-by-bit interleaving pattern is visible, not just the final number.

Related tools

See the number base converter for viewing the same values in binary, hex or octal.

Rate this tool

Was this tool useful? Your feedback helps us improve it.

No ratings yet — be the first to rate this tool.
Your rating (required)
0 / 2000

Please do not include passwords, payment details or other sensitive information.

Your feedback is sent privately to the A2Z.Tools team and will not be posted publicly.