0% found this document useful (0 votes)
36 views21 pages

1's & 2's Complement

Uploaded by

ananthan.2005.10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views21 pages

1's & 2's Complement

Uploaded by

ananthan.2005.10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Module 1 contd

Representation of Negative numbers - Complements


Digital systems (computers) must be able to handle both +ve
and -ve numbers. There are 3 ways of representing signed
integer numbers in binary

● Sign Magnitude Form


● 1’s Complement Form
● 2’s Complement Form
Sign Magnitude form.
The MSB is reserved for signed bit, and the rest of the bits are the
magnitude bits.

The MSB( left most bit) of the signed binary number is called sign bit.
If it is zero( 0 ) ,the number is positive.
when it is one ( 1 ), then the number is negative.

Eg. The 4-bit signed number representation , 0 1 1 1 represents a positive number and its magnitude
is 7 . ( Left most bit MSB is 0 it represent that it is a positive number and the remaining bits 111 show its
magnitude ). The 4-bit signed number representation 1 1 1 1 represent a negative number and its
magnitude is 7 . ( 1 in left most MSB indicates that the number is negative and the other remaining bits
represent is value/magnitude )

This representation of numbers is known as signed magnitude representation.


Advantage and disadvantage of sign magnitude form of representation

Advantage: Ease of representation.

Disadvantage:1.For a n bit representation the range will be reduced to - (2ⁿ⁻¹ - 1)


and +(2ⁿ⁻¹ – 1) as the MSB is the sign bit. 2) difficult to perform mathematical
operations . Hence this system is least used.
Reason why range is reduced

Decimal Sign magnitude


form

+0 000

+1 001

+2 010

+3 011

-0 100

-1 101

-2 110

-3 111
Add +7 & -7 in sign magnitude form

+7 = 0111

-7 = 1111

0111

+ 1111

1 0110

The answer must be 0 . when addition is done the sum is different. That is why it is
least used.
1’s complement representation
In one’s complement, positive numbers (also known as non-complements) remain
unchanged .
Negative numbers however, are represented by taking the one’s complement
(inversion, negation) of the unsigned positive number. Since positive numbers
always start with a “0”, the complement will always start with a “1” to indicate a
negative number.
The one’s complement of a negative binary number is the complement of its
positive counterpart, so to take the one’s complement of a binary number, all we
need to do is change each bit. Thus the one’s complement of “1” is “0” and vice
versa, Then the one’s complement of 10010100 is simply 01101011 as all the 1’s
are changed to 0’s and the 0’s to 1’s.
3 bit representation of binary numbers

1 = 001 1’s complement is 110

2 = 010 “ is 101

3 =011 “ is 100
0 = 000 1’s complement is 111

That is both 000 and its 1’s complement 111 represent 0 .

000 is +0 .111 is -0.


Table
Decimal 1’s complement

+0 000

+1 001

+2 010

+3 011

-3 100

-2 101

-1 110

-0 111
Range

To find the one’s complement of a binary number N as all we need do is simply


change the 1’s to 0’s and the 0’s to 1’s to give us a -N equivalent. Like the sign-
magnitude representation, one’s complement can also have n-bit notation to
represent numbers in the range from: - (2ⁿ⁻¹ - 1) and +(2ⁿ⁻¹ – 1). For example, a
4-bit representation in the one’s complement format can be used to represent
decimal numbers in the range from -7 to +7 with two representations of zero: 0000
(+0) and 1111 (-0) the same as before.
Add +7 to -7 in 1’s complement

+7 = 0111

-7 = 1000

0111

+ 1000

1111 i e -0 in 1’s complement.


Add +7 to -7 in 1’s complement

+7 = 0111

-7 = 1000

0111

+ 1000

1111 i e -0 in 1’s complement.


Decimal value of 1’s complement numbers.

Positive numbers: summing the weights of all bit positions where there are 1’s and
ignoring positions with 0’s.

Negative numbers :Assigning a negative value to the weight of the sign bit,
summing all the weights where there are 1’s and adding 1 to the result.

Eg: Determine the decimal value of the following signed binary number expressed
in 1’s complement. i) 00010111 ii) 11101000

i) 1 x 2⁴ + 1x 2² + 1x 2¹ + 1x 2⁰ = +23

ii) -1 x 2 ⁷ +1 x 2⁶ + 1 x 2⁵ + 1 x 2³ = -24+1 =-23


2’s complement numbers

In two’s complement, the positive numbers are exactly the same as before for
unsigned binary numbers. A negative number, find the 1’s complement of the
number and add 1 to it. The 2’s complement of the binary number, which when
added to its corresponding positive equivalent results in zero.
Eg: 2’s complement of -7

7 is 0111

1’s complement of 7 is 1000

+1

1001
2 more methods

1. By subtracting the given n bit number N from 2ⁿ

Eg 2’s complement of -7 by this method

7 in binary is 0111

2⁴= 10000

10000- 0111= 1001 2’s complement of -7.


2. Starting at the LSB copying down each bit upto and
including the first 1 bit encountered and complementing the
remaining bits.

Eg. express -45 using this method.

45 in binary = 00101101

11010011 is the 2’s complement.


3 bit representation

Decimal 2’s complement

0 000

+1 001

+2 010

+3 011

-4 100

-3 101

-2 110

-1 111

More negative numbers can be represented. Only one zero.


Special case: whenever a signed number has a 1 in the
sign bit and all 0’s for the magnitude bits the decimal
equivalent is - 2ⁿ, where n is the number of bits in the
magnitude. Eg. 1000= - 8.

Characteristics of 2’s complement.

1. There is only one unique 0.


2. The 2’s complement of 0 is 0.
3. Range is n-bit notation to represent numbers in the range from: - (2ⁿ⁻¹ ) and
to +(2ⁿ⁻¹ – 1).
Advantage of 2’s complement form

The main advantage of two’s complement over the previous one’s complement is
that there is no double-zero problem plus it is a lot easier to generate the two’s
complement of a signed binary number. Therefore, arithmetic operations are
relatively easier to perform when the numbers are represented in the two’s
complement format.
Decimal values of 2’s complement numbers
Decimal values of positive and negative numbers are obtained by summing the
weights in all bit positions where there are 1’s and ignoring 0’s. The weight of the
sign bit in a negative number is given a negative value.

Find the value of the following signed binary numbers expressed in 2’s
complement.

1) 0110 = 1 x 2² + 1x 2¹ = 6 or +6.
2) 10101010 = -128 + 32+8+2 = - 86
Exercise

1. Express the following decimal numbers in binary as an 8 bit sign magnitude


number. a) +29 b) -85 c) +100 d) -123
2. Express the following decimal numbers in binary as an 8 bit number in the
1’s complement form. a) +57 b) -34 c) +115 d) -99.
3. Express the following decimal numbers in binary as an 8 bit number in the
2’s complement form. a) +12 b) -68 c) +101 d) -125.
4. Determine the decimal value of each signed binary number in the sign
magnitude form. a) 10011001 b) 01110100 c) 10111111.
5. Determine the decimal value of each signed binary number in the 1’s
complement form. a) 10011001 b) 01110100 c) 10111111.
6. Determine the decimal value of each signed binary number in the 2’s
complement form. a) 10011001 b) 01110100 c) 10111111.

You might also like