gpt4 book ai didi

c - Bit Twiddling 黑客 : interleave bits the obvious way

转载 作者:太空狗 更新时间:2023-10-29 16:34:03 24 4
gpt4 key购买 nike

<分区>

我对这个问题很感兴趣

Interleave bits the obvious way

(from 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 = 100101y = 010101,结果会是什么?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com