I have the following operation in PHP:
24733 * 0x41c64e6d + 0x6073;
...and the result is: 27293242579276
With the same logic, I do the same operation in C#:
24733 * 0x41c64e6d + 0x6073;
But the result is: -1274586804
OMG, why?
I have the following operation in PHP:
24733 * 0x41c64e6d + 0x6073;
...and the result is: 27293242579276
With the same logic, I do the same operation in C#:
24733 * 0x41c64e6d + 0x6073;
But the result is: -1274586804
OMG, why?
by default c# treats number as int
when no explicit cast is specified.
so 24733 is treated as int.
int x int + int = int
and Max int is 2147483647 which is way smaller than 27293242579276. This resulted in integer overflow.
To solve the problem, use a type with higher number of bits such as decimal
you can append a letter "m" at the end of the number to tell c# you want it to be a decimal
like 24733m * 0x41c64e6d + 0x6073