Looking here, it seems that the techniques either require LUTs or loops. So, I think the most elegant way will be to use the "Obvious way" (linked) while setting y = x
prior to the calculation.
unsigned short x; // Interleave bits of x and y, so that all of the
unsigned short y; // bits of x are in the even positions and y in the odd;
unsigned int z = 0; // z gets the resulting Morton Number.
x = INPUT_PATTERN;
y = x;
for (int i = 0; i < sizeof(x) * CHAR_BIT; i++) // unroll for more speed...
{
z |= (x & 1U << i) << i | (y & 1U << i) << (i + 1);
}
Yes, I am aware it is not necessarily the "clever" solution that the OP asks for, but the other answers so far include loops/recursion as well, so why not give it a try...