2s-complement for sign integer conversion to binary

Conversion

positive value - no change E.g. 00001100

negative value, X - 2^n E.g. -00001100 Under 8-bit 1s-complement: 2^8 - 12 = 244 = 11110100

Invert the bits to get the complement

HACK Convert using 1s bit-flipping, add-1

Properties

If MSB is 1, it is negative

If MSB is 0, it is either 0 (000) or positive

Full 0s and 1s are positive and negative 0s respectively: 0000 = +0 1111 = -0

Operations

Binary addition

  1. Binary add 2 numbers
  2. Ignore carry out of MSB
  3. Check for bit overflows.

Binary subtraction

  1. Take 2s-complement of B
  2. Binary addition: complement B + A