Skip to main content
. 2025 Nov 1;25(21):6677. doi: 10.3390/s25216677
Algorithm 1 Generating Binary Encoding for the n×n Hilbert Curve
  • 1:

    Input: Area size n×n (assumed n=2m), Point coordinates (x,y){0,...,n1}2

  • 2:

    Output: Binary encoding of each point on the Hilbert curve

  • 3:

    For each point (x,y) do

  • 4:

    index0

  • 5:

    scalen/2

  • 6:

    xtempx, ytempy

  • 7:

    while scale>0 do

  • 8:

          rxbit(xtemp,scale)

  • 9:

          rybit(ytemp,scale)

  • 10:

        indexindex+scale×scale((3×rx)ry)

  • 11:

        if ry=0 then

  • 12:

            if rx=1 then

  • 13:

                 (xtemp,ytemp)(n1xtemp,n1ytemp)

  • 14:

            end if

  • 15:

            (xtemp,ytemp)(ytemp,xtemp)

  • 16:

        end if

  • 17:

        scalescale/2

  • 18:

    end while

  • 19:

    Output binary representation of index