I'm trying to convert some java code to C# and it's been working flawlessly so far but I've encountered an issue with the ^ operator. In C# Console.WriteLine(127 ^ 0xffffffff);
prints 4294967168 whereas in Java System.out.println(127 ^ 0xffffffff);
prints -128. I've been looking around to see if there is something else that I need to use instead but I haven't come across anything.
C# supports signed as well as unsigned integers (Java supports signed ones only):
unchecked {
// you want signed int
int result = (int) (127 ^ 0xffffffff);
Console.WriteLine(result);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With