gpt4 book ai didi

c# - Bitwise Barrel Shift 在 C# 中左右旋转的问题

转载 作者:行者123 更新时间:2023-12-04 13:03:37 26 4
gpt4 key购买 nike

在 C++ 中,我有这样的代码。

    static UInt32 rol(UInt32 value, UInt32 bits)
{
bits &= 31;
return ((value << bits) | (value >> (32 - bits)));
}

static UInt32 ror(UInt32 value, UInt32 bits)
{
bits &= 31;
return ((value >> bits) | (value << (32 - bits)));
}

它在 C# 中看起来如何?我认为完全相同的方式..唯一的问题

Error 2 Operator '>>' cannot be applied to operands of type 'uint' and 'uint'
Error 3 Operator '>>' cannot be applied to operands of type 'uint' and 'uint'
Error 1 Operator '<<' cannot be applied to operands of type 'uint' and 'uint'
Error 4 Operator '<<' cannot be applied to operands of type 'uint' and 'uint'

最佳答案

您应该为移位运算符中的右侧变量使用 int 类型。

关于c# - Bitwise Barrel Shift 在 C# 中左右旋转的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289316/

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