C#按位或上一个符号扩展操作使用的运营商;考虑转换为一个较小的无符号类型第一 [英] C# Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first

查看:555
本文介绍了C#按位或上一个符号扩展操作使用的运营商;考虑转换为一个较小的无符号类型第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这些警告很可能是毫无意义的。但无论如何,我可以摆脱他们?

我得到了这些警告7。

按位或上一个符号扩展操作使用的运营商;考虑转换为一个较小的无符号类型第一个

这事做与OR运算符 |

我强调什么给了警告。

  INT结果=(int)的ROR((UINT)(V76 ^(V75 | 0x862D63D3)),(UINT)(BitConverter.ToInt32(V4,72)^ 0x22));INT V11 =(int)的ROL((UINT)(int)的((V8&放大器; V10 |〜V10&放大器; 0xEFCDAAC9)+ v3的[2]  -  1126481991),17);INT v144 =(int)的ROL((UINT)(int)的((v141&放大器; V143 |〜V143&放大器; 0xEFCDAAC9)+ v3的[2]  -  1126481991),17);INT V77 =(INT)(`BitConverter.ToInt32(V4,52)| 0x96C35837`);
BitConverter.GetBytes((INT)(V30和放大器; 0x870DEA8A | V29))CopyTo从(V2,32)。INT temp24 | =(INT)(BitConverter.ToInt32(V3,48)| 0x96B4A1B4);INT V17 =(INT)(BitConverter.ToInt32(V3,12)| 0x83868A1D);


解决方案

一个快速的Web搜索显示的为警告,它带有一个解释的官方文档。问题是,我们的前pression V75 | 0x862D63D3 的形式为 INT | UINT 。这是通过促进双方计算。如果你真的想符号扩展,写成(ULONG)(长)V75 | 0x862D63D3 。如果你真的想零扩展,然后写(UINT)V75 | 0x862D63D3

 类节目{
 公共静态无效的主要()
 {
  INT V75 = int.MinValue;
  的System.Console.WriteLine({0:X},V75 | 0x862D63D3);
  的System.Console.WriteLine({0:X}(ULONG)(长)V75 | 0x862D63D3);
  的System.Console.WriteLine({0:X}(UINT)V75 | 0x862D63D3);
 }
}

此程序打印

  ffffffff862d63d3
ffffffff862d63d3
862d63d3

正如你可以看到,编译器默认为第一间pretation,这可能不是你想要的。

I know these warnings are probably pointless.. But anyway I could get rid of them?

I got 7 of these warnings.

Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first

This has something to do with the OR operator |

I highlighted what gives off the warnings.

int result = (int)ror((uint)(v76 ^ (v75 | 0x862D63D3)), (uint)(BitConverter.ToInt32(v4, 72) ^ 0x22));

int v11 = (int)rol((uint)(int)((v8 & v10 | ~v10 & 0xEFCDAAC9) + v3[2] - 1126481991), 17);

int v144 = (int)rol((uint)(int)((v141 & v143 | ~v143 & 0xEFCDAAC9) + v3[2] - 1126481991), 17);

int v77 = (int)(`BitConverter.ToInt32(v4, 52) | 0x96C35837`);


BitConverter.GetBytes((int)(v30 & 0x870DEA8A | v29)).CopyTo(v2, 32);

int temp24 |= (int)(BitConverter.ToInt32(v3, 48) | 0x96B4A1B4);

int v17 = (int)(BitConverter.ToInt32(v3, 12) | 0x83868A1D);

解决方案

A quick Web search shows the official documentation for the warning, which comes with an explanation. The problem is that the expression v75 | 0x862D63D3 is of the form int | uint. This is computed by promoting both sides to long. If you really want sign extension, write (ulong)(long)v75 | 0x862D63D3. If you really want zero-extension, then write (uint)v75 |0x862D63D3.

class Program {
 public static void Main()
 {
  int v75 = int.MinValue;
  System.Console.WriteLine("{0:x}", v75 | 0x862D63D3);
  System.Console.WriteLine("{0:x}", (ulong)(long)v75 | 0x862D63D3);
  System.Console.WriteLine("{0:x}", (uint)v75 | 0x862D63D3);
 }
}

This program prints

ffffffff862d63d3
ffffffff862d63d3
862d63d3

As you can see, the compiler defaults to the first interpretation, which is probably not what you want.

这篇关于C#按位或上一个符号扩展操作使用的运营商;考虑转换为一个较小的无符号类型第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆