I’m looking to convert this line of C code to C#:
const u64 a = 1, b = -a;
So my understanding is that both constants are unsigned 64-bit integers. If so, what is the result going to look like?
Or is the second constant actually promoted and therefore defined as a signed integer?
Due to the behaviour of negating unsigned integers, the representation of
-(u64)1is all 1s. So, after the following:Of course,
0xffffffffffffffffis also(2^64) -1, which is 18446744073709551615.In my opinion, it would have been clearer for the original programmer to instead write:
I’m not a C# programmer, but I suspect the following will work for you: