1ns and 2s Compliment
1ns and 2s Compliment
One’s Complement
The complement (or opposite) of +5 is −5. When representing
positive and negative numbers in 8-bit ones complement binary
form, the positive numbers are the same as in signed binary
notation i.e. the numbers 0 to +127 are represented as
000000002 to 011111112. However, the complement of these
numbers, that is their negative counterparts from −127 to −0, are
represented by ‘complementing’ each 1 bit of the positive binary
number to 0 and each 0 to 1.
For example:
+510 is 000001012
−510 is 111110102
Notice in the above example, that the most significant bit (msb) in
the negative number −510 is 1, just as in signed binary. The
remaining 7 bits of the negative number however are not the same
as in signed binary notation. They are just the complement of the
remaining 7 bits, and these give the value or magnitude of the
number.
And that is all there is to it! One’s complement is useful for forming the two’s
complement of a number.
Complements are used in the digital computers in order to simplify the subtraction
operation and for the logical manipulations. For each radix-r system (radix r
represents base of number system) there are two types of complements.
1's complement
The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's.
This is called as taking complement or 1's complement. Example of 1's
Complement is as follows.
2's complement
To get 1’s complement of a binary number, To get 2’s complement of a binary number,
simply invert the given number. simply invert the given number and add 1 to
the least significant bit (LSB) of given result.
1’s complement of binary number 110010 is 2’s complement of binary number 110010 is
001101 001110
Simple implementation which uses only Uses NOT gate along with full adder for
NOT gates for each input bit. each input bit.
Can be used for signed binary number Can be used for signed binary number
representation but not suitable as representation and most suitable as
ambiguous representation for number 0. unambiguous representation for all
numbers.
0 has two different representation one is -0 0 has only one representation for -0 and +0
(e.g., 1 1111 in five bit register) and second (e.g., 0 0000 in five bit register). Zero (0) is
is +0 (e.g., 0 0000 in five bit register). considered as always positive (sign bit is 0)
For k bits register, positive largest number For k bits register, positive largest number
that can be stored is (2(k-1)-1) and negative that can be stored is (2(k-1)-1) and negative
lowest number that can be stored is -(2(k-1)-1). lowest number that can be stored is -(2(k-1)).
1’s complement arithmetic operations are 2’s complement arithmetic operations are
not easier than 2’s complement because of much easier than 1’s complement because
addition of end-around-carry-bit. of there is no addition of end-around-carry-
bit.
Sign extension is used for converting a Sign extension is used for converting a
signed integer from one size to another. signed integer from one size to another.
Practice
Answers
One’s complement:
1. 0101
2. 00001111
3. 01000011 00111111
4. 01011110
Two’s complement:
1. 0110 (1010 –> 0101 + 1 = 0110)
2. 00010000
3. 10000000 (Result is the same as the original value.)
4. 10000001