Calculating range of two's complement
For a non negative value, the most significant bit is 0 and the remaining 15 bits represent the value directly.

For a negative value, the most significant bit is 1 and the remaining 15 bits represent the absolute value minus one complemented.

Example for -1:

00000000 00000001 (absolute value)
00000000 00000000 (minus one)
11111111 11111111 (complemented) --&gt; (-1 in 2's complement)


2's complement does not makes sense for unsigned numbers.

For 16 bit unsigned:

Min: 0x0000 --&gt; 0
Max: 0xFFFF --&gt; 65535


For 16 bit signed:

Min: 0x8000 --&gt; -32768
Max: 0x7FFF --&gt; 32767


2's complement is used because it simplifies sums at binary level.

Take these examples:

  00000000 00001010 (10 decimal)
 +11111111 11111001 (-7 decimal)
-------------------
1 00000000 00000011 (3 decimal) (the leftmost 1 is discarded because overflows the 16 bit sum)


  00000000 00001100 (12 decimal)
 +11111111 11101001 (-23 decimal)
-------------------
  11111111 11110101 (-11 decimal)