3 Variants

Sign-and-Magnitude (原码)

  • Represent positive and negative decimal integers in binary with the help of Sign Bit
  • Divide the number of bits into 2 parts, one part for negative number, another part for positive number

Require extra Logic Gates

1’s Complement (反码)

  • We re-can use Adder logic gates, without building extra logic circuit like a subtraction logic gates

Mathematically wrong definition of 0

  • We have +0 (when all bits are 0) & -0(when all bits are 1) under this encoding, this can be solved by 2’s Complement (补码)

2’s Complement (补码)

Integer Overflow

  • When a value is out of the range that the Datatype can hold

Check for Integer Overflow

  • If the sign of the two operand are the same, and the sign of the result is different. Then we have an Integer (整数) overflow
  • Think about how can the sum of two positive integer result in a negative number
  • And how the sum of two negative integer result in a positive number
  • The sum of a negative and positive integer guaranteed no integer overflow


Sign Bit

  • The first bit from left
  • 0 denotes positive
  • 1 denotes negative


  • All the bits in the encoding except Sign Bit