【发布时间】:2010-07-08 12:55:31
【问题描述】:
我对这个问题很感兴趣
以明显的方式交错位
(来自http://graphics.stanford.edu/~seander/bithacks.html)
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. for (int i = 0; i < sizeof(x) * CHAR_BIT; i++) // unroll for more speed... { z |= (x & 1U << i) << i | (y & 1U << i) << (i + 1); }
有人可以通过示例向我解释这是如何工作的吗?
例如,如果我们有x = 100101 和y = 010101,结果会是什么?
【问题讨论】:
-
@davit-datuashvili:请停止使用算法标签标记每个问题。
标签: c bit-manipulation bit-shift