按位桶移位的问题在C#中向左和向右旋转 [英] Problem with Bitwise Barrel Shift Rotate left and right in C#
问题描述
在C ++中,我有这样的代码.
In C++ I have code like this.
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#中看起来如何?我想同样的方式..唯一的问题
how would it look in C#? I think the same exact way.. only problem
错误2运算符'>>'无法应用于类型'uint'和'uint'的操作数
错误3运算符'>>'无法应用于类型'uint'和'uint'的操作数
错误1运算符'<<'不能应用于类型为'uint'和'uint'的操作数
错误4运算符'<<'不能应用于类型为'uint'和'uint'的操作数
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
类型.
You should use int
type for the right side variable in shift operators.
这篇关于按位桶移位的问题在C#中向左和向右旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!