C # vs VB.NET bitwise OR

Why does the OR operator in vb and C # give different results.

Console.WriteLine(0x2 | 0x80000000); output 2147483650 

http://dotnetfiddle.net/wC9AgG

 Console.WriteLine(&H2 Or &H80000000) output -2147483646 

http://dotnetfiddle.net/g4tLQ9

+6
source share
1 answer

In VB.NET &H80000000 is of type Int32 and is a negative number. In C # 0x80000000 is of type UInt32 and is a positive number. The difference between languages ​​is not in beaten OR, but in whole literals.

Most likely, the reason these types are different is because C # evolved from a language that supports unsigned types, and VB.NET evolved from a language that did not. In a language without unsigned types, the meaning &H80000000 was a negative integer.

+11
source

Source: https://habr.com/ru/post/959050/


All Articles