Morton Code Converter

Convert between Morton code (Z-order curve) and 2D coordinates (X, Y). Morton code is a space-filling curve that maps multidimensional data to one dimension while preserving locality.

Coordinates to Morton Code

Morton Code to Coordinates

Visualization

How It Works

Morton code interleaves the bits of X and Y coordinates. For example, X=3 (011) and Y=5 (101) become Morton code 27 (011011) by interleaving: 0x1y1x1y.

Example

X = 3 (binary: 011)
Y = 5 (binary: 101)
Morton Code = 27 (binary: 011011)
Interleaved: 0x0y1x1y1x1y

How to use:

  1. Coordinates to Morton Code: Enter X and Y coordinates (non-negative integers, 0-65535) and click Convert
  2. Morton Code to Coordinates: Enter a Morton code (0-4294967295) and click Convert to get X and Y coordinates
  3. View the binary representation to understand how bits are interleaved
  4. Copy the results as needed

About Morton Code

Morton code (also known as Z-order curve or Lebesgue curve) is a space-filling curve that maps multidimensional data to one dimension. It interleaves the bits of coordinates, preserving spatial locality. Morton codes are widely used in spatial indexing, database systems, and computer graphics for efficient range queries and spatial data structures. The code allows nearby points in 2D space to have similar Morton codes, making it useful for spatial indexing algorithms.