December 03, 2017

One's complement and Two's complement

❑ One's complement
❍ If MSB is 0, it is a positive number and if MSB is 1, it is a negative number.
❍ It inverts each bit to represent a negative number.
❍ It adds the Carry bit in the negative operation.
e.g. 23 - 8
  0001 0111 = 23
+ 1111 0111 = -8
───────────────
 1 0000 1110
+ 0000 0001 (+Carry 1)
───────────────
  0000 1111 = 15


❑ Two's complement
❍ If MSB is 0, it is a positive number and if MSB is 1, it is a negative number.
❍ It inverts each bit and plus 1 to represent a negative number.
❍ It don't use Carry bit in the negative operation.
❍ The Python code for converting(Link).
e.g. 23-8
  0001 0111 = 23
+ 1111 1000 = -8
───────────────
  0000 1111 = 15