我想执行位操作,以便对于给定的输入,需要交换相邻位。我如何用c语言来做到这一点? [已关闭]

问题描述 投票:0回答:1

给我的输入是 0xDEAD,预期的输出是 0xEDDA。

c bit-manipulation
1个回答
0
投票
int swapAdjacentFourBitGroups(int input)
{
    return ((input << 4) & 0xf0f0f0f0) | ((input >> 4) & 0x0f0f0f0f);
}
© www.soinside.com 2019 - 2024. All rights reserved.