Per the C standard, arithmetic for unsigned integers is performed modulo 2bit width. So, for a 32-bit integer, the negation will be taken mod 232 = 4294967296.
For a 32-bit number, then, the value you'll get if you negate a number n
is going to be 0-n = 4294967296-n
. In your specific case, assuming unsigned int
is 32 bits wide, you'd get 4294967296-1 = 4294967295 = 0xffffffff
(the number with all bits set).
The relevant text in the C standard is in §6.2.5/9:
a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type