复制整数位的最快方法是什么。
例如,
17
-> 10001
复制后:
1100000011
最佳答案
看起来像是位交错的变体。
Interleave bits the obvious way
(modified from http://graphics.stanford.edu/~seander/bithacks.html)
unsigned int x = 17; 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 | (x & 1U << i) << (i + 1); }
参见 http://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableObvious更多方法。
关于c++ - 复制整数位的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55348076/