I’m struggling with understanding the MATLAB open source about converting 2D (x, y) to 1D (d) via the Hilbert curve. The author used bitwise AND and XOR in lines 17-19:
link
function d = from2d(x, y)
d = 0;
rx = 0;
ry = 0;
m =32;
n = 2 ^ m;
s = n / 2;
while s > 0
rx = bitand( uint64(x), uint64(s), 'uint64' ) > 0;
ry = bitand( uint64(y), uint64(s), 'uint64' ) > 0;
d = d + s * s * ( bitxor((3 * rx), ry, 'uint64'));
if (ry == 0)
if (rx == 1)
x = n - 1 - x;
y = n - 1 - y;
end
t = x;
x = y;
y = t;
end
s = s / 2;
end
end
Where m is the order of the Hilbert curve. I don’t understand the role of rx and ry.
Can you explain the idea behind the use of bitwise operations?
Thanks
New contributor
PhuDo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.