1's complement and 2's complement

MG
Written by
3
In digital logic design, one of the ways to represent negative numbers is by using signed number representation. One of the commonly used signed number representation methods is 2's complement, while the other is 1's complement. 

Here are the differences between the two:

1's Complement:
In 1's complement, negative numbers are represented by taking the bitwise complement of the corresponding positive number. For example, to represent -5 in 1's complement, we take the bitwise complement of 5:


5 = 0101
-5 = 1010 (1's complement of 5)


To get the decimal value of a number represented in 1's complement, we need to determine whether the number is negative or positive. If the most significant bit (MSB) is 1, the number is negative. To get the magnitude of the negative number, we take the 1's complement of the binary number and then convert it to decimal.

The disadvantage of using 1's complement is that it has two representations of zero (+0 and -0) and also has a sign-magnitude arithmetic, which makes addition and subtraction more complicated.

2's Complement:
In 2's complement, negative numbers are represented by taking the 2's complement of the corresponding positive number. To get the 2's complement of a binary number, we first take the 1's complement of the number and then add one to it. For example, to represent -5 in 2's complement:


5 = 0101
1's complement of 5 = 1010
2's complement of 5 = 1011
-5 = 1011


To get the decimal value of a number represented in 2's complement, we use the same method as for unsigned numbers. If the MSB is 1, the number is negative. To get the magnitude of the negative number, we take the 2's complement of the binary number and then convert it to decimal.

The advantage of using 2's complement is that there is only one representation of zero, and it has a simple two's complement arithmetic for addition and subtraction.

The main difference between 1's complement and 2's complement is the way they represent negative numbers. While 1's complement uses the bitwise complement of the corresponding positive number, 2's complement uses the 2's complement of the corresponding positive number. 2's complement is widely used in digital logic design due to its simplicity and the fact that it only has one representation of zero.

Alternate explanation:
In general, we (human beings) express negative numbers by placing a minus (-) sign at the left end of the number. Similarly while representing the integers in binary format, we can leave the left-most bit be the sign bit. If the left-most bit is a zero, the integer is positive; if it is a one, it is negative.

To make it easy to design computers which do integer arithmetic, integers should obey the following rules:

(1) Zero is positive and -0 = 0
(2) The top-most bit should tell us the sign of the integer.
(3) The negative of a negative integer is the original integer ie., --55 is 55.
(4) x - y should give the same result as x + -y. That is, 8 - 3 should give us the same result as 8 + -3.
(5) Negative and positive numbers shouldn't be treated in different ways when we do multiplication and division with them.

2's complement has become the standard method of storing signed binary integers. It allows the representation of numbers in the range – (2n) to 2n-1, and has the major advantage of only having one encoding for 0.

A simple and elegant way to represent integers which obeys these rules is called 2s complement. The 2s complement of an integer is calculated by changing all bits of integer from 1 to 0 & 0 to 1, then adding 1 to the result.

1's complement addition is distinguished from the 2's complement addition typically encountered in (unsigned) computer arithmetic by how overflow bits are handled. 1's complement overflow bits are carried around back into the sum while 2's complement overflow bits are discarded. 

In general, the inverse of a number under a given mathematical operation is the value which when operated on with that number returns the identity element. The 1's complement additive inverse of a number is its bitwise complement (replace 0s with 1s and 1s with 0s). This proposal relies on a number and its complement summing to zero (the additive identity element). Actually they sum to negative zero--1's complement addition has two identity elements. Recall that an identity element under a given operation is a value which leaves any other number unchanged when the operation is applied. Under 1's complement arithmetic the addition of either zero (all 0's) or negative zero (all 1's) to a number will generate a sum equal to the original number.

1's complement addition is both associative and commutative (it forms an Abelian group over the unsigned integers), so it is immaterial whether an identity element is added to a number or the number is added to an identity element, or whether the number operates on its inverse or the inverse operates on the number--both arrangements have the same result. Also note that the operation of subtraction is equivalent to adding the inverse (complement) of the number.

Tags:

Post a Comment

3Comments

Your comments will be moderated before it can appear here. Win prizes for being an engaged reader.

  1. Thanks..its a simple and understanding tutorial of complement methods..

    ReplyDelete
  2. i love it..talaga

    ReplyDelete
Post a Comment

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!