Java has >>> (I don' think there is a <<< operator) which is the unsigned right shift operator that is not present in c#. It is there in java as java has not unsigned data types. In c# just use an unsigned type with >> operator.
// To perform int result = x >>> 5;
int x = -10;
uint u = unchecked ((uint) x);
u = u >> 5;
int result = unchecked ((int) u);
未经检查的部分仅在您处于已检查上下文中时才相关当然。)
根据我的经验,当您通常想要在 Java 中使用 >>> 时,您只需使用无符号类型来开始C#。
The simplest (or at least most logical) equivalent is effectively an unchecked cast to the equivalent unsigned type, followed by a normal shift and then potentially a cast back again:
// To perform int result = x >>> 5;
int x = -10;
uint u = unchecked ((uint) x);
u = u >> 5;
int result = unchecked ((int) u);
(The unchecked part is only relevant if you're otherwise in a checked context, of course.)
In my experience, times where you normally want to use >>> in Java, you'd just use unsigned types to start with in C#.
发布评论
评论(4)
没有 C# 等效项,如果您在左侧使用无符号值,则 C# 中的
>>
将执行与 java 中>>>
相同的功能。因此,您需要进行投射才能获得所需的效果。
There is no c# equivalent, if you use an unsigned value on the left,
>>
in c# will perform the same function as>>>
in java.You therefore need to cast to get the desired effect.
Java 有
>>>
(我不认为有<<<
运算符),它是无符号右移运算符,不存在于c#. java中就有这个,因为java没有无符号数据类型。在 C# 中,只需使用带有>>
运算符的无符号类型。Java has
>>>
(I don' think there is a<<<
operator) which is the unsigned right shift operator that is not present in c#. It is there in java as java has not unsigned data types. In c# just use an unsigned type with>>
operator.>>>
是Java中的无符号移位运算。它们在 C# 中没有等效项,因为 C# 支持无符号整数,因此您可以直接对它们进行移位。
>>>
is an unsigned shift operations in Java.They don't have an equivalent in C# because C# supports unsigned integers and hence you can just shift on those.
最简单(或至少最合乎逻辑)的等效方法实际上是对等效无符号类型进行未经检查的强制转换,然后进行正常移位,然后可能再次强制转换:(
未经检查的部分仅在您处于已检查上下文中时才相关当然。)
根据我的经验,当您通常想要在 Java 中使用
>>>
时,您只需使用无符号类型来开始C#。The simplest (or at least most logical) equivalent is effectively an unchecked cast to the equivalent unsigned type, followed by a normal shift and then potentially a cast back again:
(The unchecked part is only relevant if you're otherwise in a checked context, of course.)
In my experience, times where you normally want to use
>>>
in Java, you'd just use unsigned types to start with in C#.