Programming


2's Compliment Representation for Signed Integers


Calculating 2's Compliment

A Positive Number
is represented as a simple unsigned binary.
A Negative Number
is represented as the binary number that when added to a positive number of the same magnitude equals zero.
To form a negative number:

For example,

Positive Integer 4 0000 0100
Compliment of 4
+ 1
1111 1011
0000 0001
Negative Integer 4 1111 1100

IntegerTwo's Compliment
30000 0011
20000 0010
10000 0001
00000 0000
-11111 1111
-21111 1110
-31111 1101
Most Significant Bit (MSB) indicates the sign of the integer.
 
If MSB = 0, then the number is greater than or equal to 0.
 
If MSB = 1, then the number is less than 0.

2's Compliment Arithmetic

Addition      
5 + (-3):  0000 0101(+5)
 + 1111 1101
(-3)
   0000 0010(+2)

Subtraction
3 - 5:  0000 0011(+3)
 + 1111 1011
(-5)
   1111 1110(-2)

Multiplication
3 × (-5):  0000 0011(+3)
 × 1111 1011
(-5)
   1111 0001(-15)

Division
7 ÷ 3:  0000 0111(+7)   0000 0100(+4) 7 ÷ 3 = 2 with remainder of 1
 + 1111 1101
(-3) + 1111 1101
(-3)
   0000 0100(+4)   0000 0001(+1)


Notes

Rules of Binary Addition
  1. 0 + 0 = 0
  2. 0 + 1 = 1
  3. 1 + 0 = 1
  4. 1 + 1 = 0, and carry 1 to the next more significant bit
Rules of Binary Subtraction
  1. 0 - 0 = 0
  2. 0 - 1 = 1, and borrow 1 from the next more significant bit
  3. 1 - 0 = 1
  4. 1 - 1 = 0
Rules of Binary Multiplication
  1. 0 x 0 = 0
  2. 0 x 1 = 0
  3. 1 x 0 = 0
  4. 1 x 1 = 1, and no carry or borrow bits

[  Index  |  Technical Notes Page  ]

This page is for INFORMATIONAL PURPOSES ONLY.

Page author: Dawn Rorvik (rorvikd@evergreen.edu)
Last modified: 02/06/1999