0%

CSharp bit循环移位

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/// <summary>
/// 循环移位
/// </summary>
/// <param name="val">输入的数字</param>
/// <param name="iShiftBit">要移几位</param>
/// <param name="isLeft">移位的方向</param>
/// <returns>移位后的数字</returns>
private static uint CycleShift(uint val, int iShiftBit, bool isLeft)
{
uint temp = 0;
uint result = 0;
temp |= val;
if (isLeft)
{
val <<= iShiftBit;
temp >>= (32 - iShiftBit);
result = val | temp;
}
else
{
val >>= iShiftBit;
temp <<= (32 - iShiftBit);
result = val | temp;
}
return result;
}