As a simple example, to illustrate what happens, think about the binary representation of a negative number. The easiest way to do this is to have the highest bit denoting a negative sign: 0 = hollow, 1 = negative
0001 = 1 0011 = 3 1100 = -4 0100 = 4 1011 = -3 1111 = -7 etc so when you convert -7 to an unsigned int, it becomes 15. Converting -1 to an unsigned int, it becomes 9.
In fact, Two additions are used to represent binary numbers to prevent the presence of +0 and -0.
See wiki article: http://en.wikipedia.org/wiki/Two%27s_complement
source share