Fixing the C# compiler warning about bitwise-or and sign-extended operands

Posted: (EET/GMT+2)

 

Earlier this week, I was working on a project to bring barcode scanning features for Windows Phone 7 using the ZXing libraries. Now, while integrating the code into the project, I got a plenty of C# compiler warnings about several things.

However, one of the warnings struck my eye, as I'm pretty sure I've not run into this warning before in production code: "Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first". This is the C# compiler's warning CS0675, documented here.

In my case, I got this warning from the file Detector.cs, and fixing was easy. The MSDN documentation above gives a straight-forward solution: typecast one of the operators to an unsigned type first, and you are good to go!