我不明白循环移位。
我搜索并找到了以下方法,但输入的值没有给出预期的结果:
public static uint RotateLeft(this uint value, int count)
{
return (value << count) | (value >> (32 - count));
}
Run Code Online (Sandbox Code Playgroud)
输入应在移位时间时211给出。1583
问题是您的预期结果是基于字节的,而您的代码是基于 32 位的。对于字节,请尝试以下操作:
public static byte RotateLeft(byte value, int count)
{
return (byte)((value << count) | (value >> (8 - count)));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
245 次 |
| 最近记录: |