java
sql
php
c
xml
ajax
python
mysql
linux
android
objective-c
visual-studio
flash
json
algorithm
facebook
cocoa
apache
jsp
postgresql
Due to the behaviour of negating unsigned integers, the representation of -(u64)1 is all 1s. So, after the following:
-(u64)1
const u64 a = 1, b = -a; // a is now 0x0000000000000001 // b is now 0xffffffffffffffff
Of course, 0xffffffffffffffff is also (2^64) -1, which is 18446744073709551615.
0xffffffffffffffff
(2^64) -1
In my opinion, it would have been clearer for the original programmer to instead write:
const u64 a = 1, b = ~(u64)0;
I'm not a C# programmer, but I suspect the following will work for you:
const ulong b = ~(ulong)0;
This would be the equivalent C#:
const ulong a = 1, b = unchecked((ulong)-1);
Or more simply:
const ulong a = 1, b = 18446744073709551615;
The C# compiler will try to protect you from accidentally negiting an unsigned integer, but you can force it like this:
ulong a = 1; ulong b = (ulong)-(long)a;
The result will be exactly the same bunch of bits as when negating a signed integer (i.e. two's complement), the only difference is how these bits are interpreted.
You get an ambiguous invocation error because -1 is not possible as an unsigned type (see comment below). You would have to use Int64 as type (which equals long).
When using long as type then the result will be a = 1, b = -1 and both longs.