C # bitwise XOR (^) compared to Java bitwise XOR (^)

I am trying to convert some Java code to C # and it has been working flawlessly so far, but I ran into a problem with the ^ operator. In C # Console.WriteLine(127 ^ 0xffffffff); prints 4294967168, whereas in Java System.out.println(127 ^ 0xffffffff); prints -128. I searched around to see if there was anything else I needed to use, but I did not see anything.

+6
source share
1 answer

C # supports signed as well as unsigned integers (only Java supports only signed):

  unchecked { // you want signed int int result = (int) (127 ^ 0xffffffff); Console.WriteLine(result); } 
+8
source

All Articles