我想了解什么是位交错。 我有一个例子:
a: 011
b: 101
---
c: 100111
据我所知,数字“a”的位在结果中的成对位置上,而数字“b”的位在损害位置上。 但为什么交错以数字“b”开头呢?有人知道这个规则吗?
我将在 Objective-C 中编写规则,因此非常欢迎与该语言相关的任何优化。
谢谢!
最佳答案
我找到了!
long x = 3; // Interleave bits of x and y, so that all of the
long y = 5; // bits of x are in the even positions and y in the odd;
long long z = 0; // z gets the resulting Morton Number.
for (int i = 0; i < sizeof(x) * CHAR_BIT; i++) {
z |= (x & 1U << i) << i | (y & 1U << i) << (i + 1);
}
此代码执行位交织。如您所见,结果是一个莫顿数。 我希望这会对某人有所帮助! :)
关于objective-c - Objective-c 中的位交织,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379844/