gpt4 book ai didi

c# - C#中逻辑右移的代码是什么?

转载 作者:行者123 更新时间:2023-12-05 08:16:31 25 4
gpt4 key购买 nike

我正在尝试将具有逻辑右移 (>>>) ( Difference between >>> and >> ) 的 Java 代码转换为 C#

Java代码是

 return hash >>> 24 ^ hash & 0xFFFFFF;

C# 被标记为 >>> 为语法错误。

如何解决?

更新 1人们建议在 C# 中使用 >>>,但它并没有解决问题。

System.out.println("hash 1 !!! = " + (-986417464>>>24));

是197

但是

Console.WriteLine("hash 1 !!! = " + (-986417464 >> 24));

是-59

谢谢!

最佳答案

Java 需要引入>>>,因为它唯一的无符号类型是char,它的操作是在整数中完成的。

另一方面,C# 有无符号类型,它执行右移而不带符号扩展:

uint h = (uint)hash;
return h >> 24 ^ h & 0xFFFFFF;

关于c# - C#中逻辑右移的代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41740592/

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