Compiler Warning (level 3) CS0675
Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first
The compiler implicitly widened and sign-extended a variable, and then used the resulting value in a bitwise OR operation. This can result in unexpected behavior.
The following sample generates CS0675:
// CS0675.cs
// compile with: /W:3
using System;
public class sign
{
public static void Main()
{
int hi = 1;
int lo = -1;
long value = (((long)hi) << 32) | lo; // CS0675, value contains -1 (0xffffffff_ffffffff)
// try the following line instead
// long value = (((long)hi) << 32) | ((uint)lo); // correct, value contains 8589934591 (0x00000001_ffffffff)
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for